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

Commit7915152

Browse files
committed
pathman:
* recursively disable inheritance for subqueries
1 parent4d05145 commit7915152

File tree

1 file changed

+56
-77
lines changed

1 file changed

+56
-77
lines changed

‎contrib/pathman/pathman.c

Lines changed: 56 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ static void my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry
3333
staticPlannedStmt*my_planner_hook(Query*parse,intcursorOptions,ParamListInfoboundParams);
3434

3535
staticvoidappend_child_relation(PlannerInfo*root,RelOptInfo*rel,Indexrti,RangeTblEntry*rte,intchildOID);
36+
staticvoidset_pathkeys(PlannerInfo*root,RelOptInfo*childrel,Path*path);
37+
staticvoiddisable_inheritance(Query*parse);
3638

3739
staticList*walk_expr_tree(Expr*expr,constPartRelationInfo*prel);
3840
staticintmake_hash(constPartRelationInfo*prel,intvalue);
@@ -93,35 +95,53 @@ PlannedStmt *
9395
my_planner_hook(Query*parse,intcursorOptions,ParamListInfoboundParams)
9496
{
9597
PlannedStmt*result;
98+
99+
if (initialization_needed)
100+
init();
101+
102+
disable_inheritance(parse);
103+
result=standard_planner(parse,cursorOptions,boundParams);
104+
returnresult;
105+
}
106+
107+
/*
108+
*
109+
*/
110+
staticvoid
111+
disable_inheritance(Query*parse)
112+
{
96113
RangeTblEntry*rte;
97114
ListCell*lc;
98115
PartRelationInfo*prel;
99116

100-
if (initialization_needed)
101-
init();
117+
if (parse->commandType!=CMD_SELECT)
118+
return;
102119

103-
/* Disable inheritance for relations covered by pathman (only for SELECT for now) */
104-
if (parse->commandType==CMD_SELECT)
120+
foreach(lc,parse->rtable)
105121
{
106-
foreach(lc,parse->rtable)
122+
rte= (RangeTblEntry*)lfirst(lc);
123+
switch(rte->rtekind)
107124
{
108-
rte= (RangeTblEntry*)lfirst(lc);
109-
if (rte->inh)
110-
{
111-
/* look up this relation in pathman relations */
112-
prel= (PartRelationInfo*)
113-
hash_search(relations, (constvoid*)&rte->relid,HASH_FIND,0);
114-
if (prel!=NULL)
115-
rte->inh= false;
116-
}
125+
caseRTE_RELATION:
126+
if (rte->inh)
127+
{
128+
/* look up this relation in pathman relations */
129+
prel= (PartRelationInfo*)
130+
hash_search(relations, (constvoid*)&rte->relid,HASH_FIND,0);
131+
if (prel!=NULL)
132+
rte->inh= false;
133+
}
134+
break;
135+
caseRTE_SUBQUERY:
136+
/* recursively disable inheritance for subqueries */
137+
disable_inheritance(rte->subquery);
138+
break;
139+
default:
140+
break;
117141
}
118142
}
119-
120-
result=standard_planner(parse,cursorOptions,boundParams);
121-
returnresult;
122143
}
123144

124-
125145
staticvoid
126146
my_shmem_startup(void)
127147
{
@@ -163,7 +183,6 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
163183
children=lappend_int(children,prel->children[i]);
164184

165185
/* Run over restrictions and collect children partitions */
166-
ereport(LOG, (errmsg("Checking restrictions")));
167186
foreach(lc,rel->baserestrictinfo)
168187
{
169188
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
@@ -176,14 +195,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
176195
}
177196
}
178197

179-
// if (children == NIL)
180-
// {
181-
// ereport(LOG, (errmsg("Restrictions empty. Copy children from partrel")));
182-
// // children = get_children_oids(partrel);
183-
// // children = list_copy(partrel->children);
184-
185-
// }
186-
198+
/* expand simple_rte_array and simple_rel_array */
187199
if (list_length(children)>0)
188200
{
189201
RelOptInfo**new_rel_array;
@@ -212,65 +224,16 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
212224
root->simple_rte_array=new_rte_array;
213225
/* TODO: free old arrays */
214226
}
215-
else
216-
{
217-
ereport(LOG, (errmsg("Children count is 0")));
218-
}
219-
220-
ereport(LOG, (errmsg("Appending children")));
221-
// Добавляем самого себя
222-
// append_child_relation(root, rel, rti, rte, partrel->oid);
223-
// {
224-
// AppendRelInfo *appinfo;
225-
// appinfo = makeNode(AppendRelInfo);
226-
// appinfo->parent_relid = rti;
227-
// appinfo->child_relid = rti;
228-
// appinfo->parent_reloid = rte->relid;
229-
// root->append_rel_list = lappend(root->append_rel_list, appinfo);
230-
// }
231-
// root->hasInheritedTarget = true;
232227

233228
foreach(lc,children)
234229
{
235230
childOID= (Oid)lfirst_int(lc);
236231
append_child_relation(root,rel,rti,rte,childOID);
237-
// root->simple_rel_array_size += 1;
238232
}
239233

240234
/* TODO: clear old path list */
241235
rel->pathlist=NIL;
242-
// if (root->parse->commandType == CMD_SELECT)
243236
set_append_rel_pathlist(root,rel,rti,rte);
244-
// else
245-
// {
246-
// set_plain_rel_pathlist(root, rel, rte);
247-
// /* Set plin pathlist for each child relation */
248-
// intparentRTindex = rti;
249-
// ListCell *l;
250-
// foreach(l, root->append_rel_list)
251-
// {
252-
// AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
253-
// intchildRTindex;
254-
// RangeTblEntry *childRTE;
255-
// RelOptInfo *childrel;
256-
257-
// /* append_rel_list contains all append rels; ignore others */
258-
// if (appinfo->parent_relid != parentRTindex || appinfo->parent_relid == rti)
259-
// continue;
260-
261-
// /* Re-locate the child RTE and RelOptInfo */
262-
// childRTindex = appinfo->child_relid;
263-
// // childRTE = root->simple_rte_array[childRTindex];
264-
// // childrel = root->simple_rel_array[childRTindex];
265-
// root->simple_rel_array[childRTindex] = NULL;
266-
267-
// /*
268-
// * Compute the child's access paths.
269-
// */
270-
// // set_plain_rel_pathlist(root, childrel, childRTE);
271-
// // set_cheapest(childrel);
272-
// }
273-
// }
274237
}
275238

276239
/* Invoke original hook if needed */
@@ -700,6 +663,7 @@ static void
700663
set_plain_rel_pathlist(PlannerInfo*root,RelOptInfo*rel,RangeTblEntry*rte)
701664
{
702665
Relidsrequired_outer;
666+
Path*path;
703667

704668
/*
705669
* We don't support pushing join clauses into the quals of a seqscan, but
@@ -709,7 +673,9 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
709673
required_outer=rel->lateral_relids;
710674

711675
/* Consider sequential scan */
712-
add_path(rel,create_seqscan_path(root,rel,required_outer,0));
676+
path=create_seqscan_path(root,rel,required_outer,0);
677+
add_path(rel,path);
678+
set_pathkeys(root,rel,path);
713679

714680
/* Consider index scans */
715681
create_index_paths(root,rel);
@@ -794,6 +760,19 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
794760

795761
}
796762

763+
void
764+
set_pathkeys(PlannerInfo*root,RelOptInfo*childrel,Path*path)
765+
{
766+
ListCell*lc;
767+
PathKey*pathkey;
768+
769+
foreach (lc,root->sort_pathkeys)
770+
{
771+
pathkey= (PathKey*)lfirst(lc);
772+
path->pathkeys=lappend(path->pathkeys,pathkey);
773+
}
774+
}
775+
797776
staticList*
798777
accumulate_append_subpath(List*subpaths,Path*path)
799778
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp