Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commited178ad

Browse files
committed
introduce 'planner_tree_modification' subsystem for Plan- and Query- tree modification, refactoring, new query tree walker (fix issue #53)
1 parent0457402 commited178ad

File tree

11 files changed

+692
-527
lines changed

11 files changed

+692
-527
lines changed

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.o \
55
src/runtimeappend.o src/runtime_merge_append.o src/pg_pathman.o src/rangeset.o\
66
src/pl_funcs.o src/pl_range_funcs.o src/pl_hash_funcs.o src/pathman_workers.o\
77
src/hooks.o src/nodes_common.o src/xact_handling.o src/copy_stmt_hooking.o\
8-
src/pg_compat.o$(WIN32RES)
8+
src/planner_tree_modification.o src/pg_compat.o$(WIN32RES)
99

1010
EXTENSION = pg_pathman
1111
EXTVERSION = 1.1

‎expected/pathman_basic.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ SELECT COUNT(*) FROM ONLY test.num_range_rel;
191191
(1 row)
192192

193193
SELECT * FROM ONLY test.range_rel UNION SELECT * FROM test.range_rel;
194-
ERROR: It is prohibited toquerypartitioned tablesboth with andwithout ONLY modifier
194+
ERROR: It is prohibited toapply ONLY modifier topartitioned tableswhich have already been mentionedwithout ONLY
195195
SET pg_pathman.enable_runtimeappend = OFF;
196196
SET pg_pathman.enable_runtimemergeappend = OFF;
197197
VACUUM;

‎src/hooks.c

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include"init.h"
1414
#include"partition_filter.h"
1515
#include"pg_compat.h"
16+
#include"planner_tree_modification.h"
1617
#include"runtimeappend.h"
1718
#include"runtime_merge_append.h"
1819
#include"utils.h"
@@ -202,8 +203,12 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
202203
return;/* pg_pathman is not ready */
203204

204205
/* This works only for SELECT queries (at least for now) */
205-
if (root->parse->commandType!=CMD_SELECT||
206-
!list_member_oid(inheritance_enabled_relids,rte->relid))
206+
if (root->parse->commandType!=CMD_SELECT)
207+
return;
208+
209+
/* Skip if this table is not allowed to act as parent (see FROM ONLY) */
210+
if (PARENTHOOD_DISALLOWED==get_parenthood_status(root->query_level,
211+
rte->relid))
207212
return;
208213

209214
/* Proceed iff relation 'rel' is partitioned */
@@ -223,8 +228,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
223228
if (prel->parttype==PT_RANGE)
224229
{
225230
/*
226-
* Get pathkeys for ascending and descending sort by partition
227-
* column
231+
* Get pathkeys for ascending and descending sort by partition column
228232
*/
229233
List*pathkeys;
230234
Var*var;
@@ -438,29 +442,11 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
438442
proc((planned_stmt)->rtable, (Plan *) lfirst(lc)); \
439443
} while (0)
440444

441-
PlannedStmt*result;
445+
PlannedStmt*result;
442446

443-
/*FIXME: fix these commands (traverse wholequery tree) */
447+
/*Modifyquery tree if needed */
444448
if (IsPathmanReady())
445-
{
446-
switch(parse->commandType)
447-
{
448-
caseCMD_SELECT:
449-
disable_inheritance(parse);
450-
rowmark_add_tableoids(parse);/* add attributes for rowmarks */
451-
break;
452-
453-
caseCMD_UPDATE:
454-
caseCMD_DELETE:
455-
disable_inheritance_cte(parse);
456-
disable_inheritance_subselect(parse);
457-
handle_modification_query(parse);
458-
break;
459-
460-
default:
461-
break;
462-
}
463-
}
449+
pathman_transform_query(parse);
464450

465451
/* Invoke original hook if needed */
466452
if (planner_hook_next)
@@ -475,12 +461,10 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
475461

476462
/* Add PartitionFilter node for INSERT queries */
477463
ExecuteForPlanTree(result,add_partition_filters);
478-
}
479464

480-
list_free(inheritance_disabled_relids);
481-
list_free(inheritance_enabled_relids);
482-
inheritance_disabled_relids=NIL;
483-
inheritance_enabled_relids=NIL;
465+
/* Free all parenthood lists (see pathman_transform_query()) */
466+
reset_parenthood_statuses();
467+
}
484468

485469
returnresult;
486470
}
@@ -516,9 +500,6 @@ pathman_post_parse_analysis_hook(ParseState *pstate, Query *query)
516500
{
517501
load_config();/* perform main cache initialization */
518502
}
519-
520-
inheritance_disabled_relids=NIL;
521-
inheritance_enabled_relids=NIL;
522503
}
523504

524505
/*

‎src/partition_filter.c

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include"init.h"
1212
#include"nodes_common.h"
1313
#include"partition_filter.h"
14+
#include"planner_tree_modification.h"
1415
#include"utils.h"
1516

1617
#include"foreign/fdwapi.h"
@@ -63,7 +64,6 @@ CustomExecMethodspartition_filter_exec_methods;
6364

6465

6566
staticestate_mod_data*fetch_estate_mod_data(EState*estate);
66-
staticvoidpartition_filter_visitor(Plan*plan,void*context);
6767
staticList*pfilter_build_tlist(List*tlist);
6868
staticIndexappend_rte_to_estate(EState*estate,RangeTblEntry*rte);
6969
staticintappend_rri_to_estate(EState*estate,ResultRelInfo*rri);
@@ -112,17 +112,6 @@ init_partition_filter_static_data(void)
112112
}
113113

114114

115-
/*
116-
* Add PartitionFilter nodes to the plan tree
117-
*/
118-
void
119-
add_partition_filters(List*rtable,Plan*plan)
120-
{
121-
if (pg_pathman_enable_partition_filter)
122-
plan_tree_walker(plan,partition_filter_visitor,rtable);
123-
}
124-
125-
126115
/*
127116
* Initialize ResultPartsStorage (hash table etc).
128117
*/
@@ -804,36 +793,3 @@ pfilter_build_tlist(List *tlist)
804793

805794
returnresult_tlist;
806795
}
807-
808-
/*
809-
* Add partition filters to ModifyTable node's children.
810-
*
811-
* 'context' should point to the PlannedStmt->rtable.
812-
*/
813-
staticvoid
814-
partition_filter_visitor(Plan*plan,void*context)
815-
{
816-
List*rtable= (List*)context;
817-
ModifyTable*modify_table= (ModifyTable*)plan;
818-
ListCell*lc1,
819-
*lc2;
820-
821-
/* Skip if not ModifyTable with 'INSERT' command */
822-
if (!IsA(modify_table,ModifyTable)||modify_table->operation!=CMD_INSERT)
823-
return;
824-
825-
Assert(rtable&&IsA(rtable,List));
826-
827-
forboth (lc1,modify_table->plans,lc2,modify_table->resultRelations)
828-
{
829-
Indexrindex=lfirst_int(lc2);
830-
Oidrelid=getrelid(rindex,rtable);
831-
constPartRelationInfo*prel=get_pathman_relation_info(relid);
832-
833-
/* Check that table is partitioned */
834-
if (prel)
835-
lfirst(lc1)=make_partition_filter((Plan*)lfirst(lc1),
836-
relid,
837-
modify_table->onConflictAction);
838-
}
839-
}

‎src/partition_filter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ extern CustomExecMethodspartition_filter_exec_methods;
9393

9494
voidinit_partition_filter_static_data(void);
9595

96-
voidadd_partition_filters(List*rtable,Plan*plan);
97-
9896
/* ResultPartsStorage init\fini\scan function */
9997
voidinit_result_parts_storage(ResultPartsStorage*parts_storage,
10098
EState*estate,

‎src/pathman.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,6 @@ typedef enum
106106
}search_rangerel_result;
107107

108108

109-
/*
110-
* The list of partitioned relation relids that must be handled by pg_pathman
111-
*/
112-
externList*inheritance_enabled_relids;
113-
114-
/*
115-
* This list is used to ensure that partitioned relation isn't used both
116-
* with and without ONLY modifiers
117-
*/
118-
externList*inheritance_disabled_relids;
119-
120109
/*
121110
* pg_pathman's global state.
122111
*/
@@ -133,11 +122,6 @@ search_rangerel_result search_range_partition_eq(const Datum value,
133122

134123
uint32hash_to_part_index(uint32value,uint32partitions);
135124

136-
voidhandle_modification_query(Query*parse);
137-
voiddisable_inheritance(Query*parse);
138-
voiddisable_inheritance_cte(Query*parse);
139-
voiddisable_inheritance_subselect(Query*parse);
140-
141125
/* copied from allpaths.h */
142126
voidset_append_rel_size(PlannerInfo*root,RelOptInfo*rel,
143127
Indexrti,RangeTblEntry*rte);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp