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

Commit0137664

Browse files
committed
pathman: use comparassion function from data type for binary search
1 parent2ca82a8 commit0137664

File tree

1 file changed

+77
-63
lines changed

1 file changed

+77
-63
lines changed

‎contrib/pathman/pathman.c

Lines changed: 77 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ 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);
3836

3937
staticList*walk_expr_tree(Expr*expr,constPartRelationInfo*prel);
4038
staticintmake_hash(constPartRelationInfo*prel,intvalue);
@@ -95,53 +93,35 @@ PlannedStmt *
9593
my_planner_hook(Query*parse,intcursorOptions,ParamListInfoboundParams)
9694
{
9795
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-
{
11396
RangeTblEntry*rte;
11497
ListCell*lc;
11598
PartRelationInfo*prel;
11699

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

120-
foreach(lc,parse->rtable)
103+
/* Disable inheritance for relations covered by pathman (only for SELECT for now) */
104+
if (parse->commandType==CMD_SELECT)
121105
{
122-
rte= (RangeTblEntry*)lfirst(lc);
123-
switch(rte->rtekind)
106+
foreach(lc,parse->rtable)
124107
{
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;
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+
}
141117
}
142118
}
119+
120+
result=standard_planner(parse,cursorOptions,boundParams);
121+
returnresult;
143122
}
144123

124+
145125
staticvoid
146126
my_shmem_startup(void)
147127
{
@@ -183,6 +163,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
183163
children=lappend_int(children,prel->children[i]);
184164

185165
/* Run over restrictions and collect children partitions */
166+
ereport(LOG, (errmsg("Checking restrictions")));
186167
foreach(lc,rel->baserestrictinfo)
187168
{
188169
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
@@ -195,7 +176,14 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
195176
}
196177
}
197178

198-
/* expand simple_rte_array and simple_rel_array */
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+
199187
if (list_length(children)>0)
200188
{
201189
RelOptInfo**new_rel_array;
@@ -224,16 +212,65 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
224212
root->simple_rte_array=new_rte_array;
225213
/* TODO: free old arrays */
226214
}
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;
227232

228233
foreach(lc,children)
229234
{
230235
childOID= (Oid)lfirst_int(lc);
231236
append_child_relation(root,rel,rti,rte,childOID);
237+
// root->simple_rel_array_size += 1;
232238
}
233239

234240
/* TODO: clear old path list */
235241
rel->pathlist=NIL;
242+
// if (root->parse->commandType == CMD_SELECT)
236243
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+
// }
237274
}
238275

239276
/* Invoke original hook if needed */
@@ -317,11 +354,7 @@ change_varnos(Node *node, Oid old_varno, Oid new_varno)
317354
change_varno_walker(node,&context);
318355
}
319356

320-
<<<<<<<HEAD
321357
staticbool
322-
=======
323-
bool
324-
>>>>>>>pathman:
325358
change_varno_walker(Node*node,change_varno_context*context)
326359
{
327360
if (node==NULL)
@@ -663,7 +696,6 @@ static void
663696
set_plain_rel_pathlist(PlannerInfo*root,RelOptInfo*rel,RangeTblEntry*rte)
664697
{
665698
Relidsrequired_outer;
666-
Path*path;
667699

668700
/*
669701
* We don't support pushing join clauses into the quals of a seqscan, but
@@ -673,9 +705,7 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
673705
required_outer=rel->lateral_relids;
674706

675707
/* Consider sequential scan */
676-
path=create_seqscan_path(root,rel,required_outer,0);
677-
add_path(rel,path);
678-
set_pathkeys(root,rel,path);
708+
add_path(rel,create_seqscan_path(root,rel,required_outer,0));
679709

680710
/* Consider index scans */
681711
create_index_paths(root,rel);
@@ -760,19 +790,6 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
760790

761791
}
762792

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-
776793
staticList*
777794
accumulate_append_subpath(List*subpaths,Path*path)
778795
{
@@ -827,9 +844,6 @@ on_partitions_removed(PG_FUNCTION_ARGS) {
827844
prel= (PartRelationInfo*)
828845
hash_search(relations, (constvoid*)&relid,HASH_FIND,0);
829846

830-
if (!prel)
831-
PG_RETURN_NULL();
832-
833847
/* remove children relations */
834848
switch (prel->parttype)
835849
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp