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

Commitd723f56

Browse files
committed
Reorganize planner code moved inb60c397
It seems modules are better defined like this instead of the originalsplit.Per complaints from David Rowley as well as Amit Langote's self review.Discussion:https://postgr.es/m/CAKJS1f988rsyhwvLgfT-y1UCYUfXDOv67ENQk=v24OxhsZOzZw@mail.gmail.com
1 parent304e9f0 commitd723f56

File tree

4 files changed

+148
-151
lines changed

4 files changed

+148
-151
lines changed

‎src/backend/optimizer/path/joinrels.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ static void try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1,
4444
RelOptInfo*rel2,RelOptInfo*joinrel,
4545
SpecialJoinInfo*parent_sjinfo,
4646
List*parent_restrictlist);
47+
staticSpecialJoinInfo*build_child_join_sjinfo(PlannerInfo*root,
48+
SpecialJoinInfo*parent_sjinfo,
49+
Relidsleft_relids,Relidsright_relids);
4750
staticintmatch_expr_to_partition_keys(Expr*expr,RelOptInfo*rel,
4851
boolstrict_op);
4952

@@ -1417,6 +1420,48 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
14171420
}
14181421
}
14191422

1423+
/*
1424+
* Construct the SpecialJoinInfo for a child-join by translating
1425+
* SpecialJoinInfo for the join between parents. left_relids and right_relids
1426+
* are the relids of left and right side of the join respectively.
1427+
*/
1428+
staticSpecialJoinInfo*
1429+
build_child_join_sjinfo(PlannerInfo*root,SpecialJoinInfo*parent_sjinfo,
1430+
Relidsleft_relids,Relidsright_relids)
1431+
{
1432+
SpecialJoinInfo*sjinfo=makeNode(SpecialJoinInfo);
1433+
AppendRelInfo**left_appinfos;
1434+
intleft_nappinfos;
1435+
AppendRelInfo**right_appinfos;
1436+
intright_nappinfos;
1437+
1438+
memcpy(sjinfo,parent_sjinfo,sizeof(SpecialJoinInfo));
1439+
left_appinfos=find_appinfos_by_relids(root,left_relids,
1440+
&left_nappinfos);
1441+
right_appinfos=find_appinfos_by_relids(root,right_relids,
1442+
&right_nappinfos);
1443+
1444+
sjinfo->min_lefthand=adjust_child_relids(sjinfo->min_lefthand,
1445+
left_nappinfos,left_appinfos);
1446+
sjinfo->min_righthand=adjust_child_relids(sjinfo->min_righthand,
1447+
right_nappinfos,
1448+
right_appinfos);
1449+
sjinfo->syn_lefthand=adjust_child_relids(sjinfo->syn_lefthand,
1450+
left_nappinfos,left_appinfos);
1451+
sjinfo->syn_righthand=adjust_child_relids(sjinfo->syn_righthand,
1452+
right_nappinfos,
1453+
right_appinfos);
1454+
sjinfo->semi_rhs_exprs= (List*)adjust_appendrel_attrs(root,
1455+
(Node*)sjinfo->semi_rhs_exprs,
1456+
right_nappinfos,
1457+
right_appinfos);
1458+
1459+
pfree(left_appinfos);
1460+
pfree(right_appinfos);
1461+
1462+
returnsjinfo;
1463+
}
1464+
14201465
/*
14211466
* Returns true if there exists an equi-join condition for each pair of
14221467
* partition keys from given relations being joined.

‎src/backend/optimizer/util/appendinfo.c

Lines changed: 44 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
#include"postgres.h"
1616

1717
#include"access/htup_details.h"
18-
#include"access/sysattr.h"
1918
#include"nodes/makefuncs.h"
2019
#include"nodes/nodeFuncs.h"
2120
#include"optimizer/appendinfo.h"
2221
#include"parser/parsetree.h"
23-
#include"utils/rel.h"
2422
#include"utils/lsyscache.h"
23+
#include"utils/rel.h"
2524
#include"utils/syscache.h"
2625

2726

@@ -38,8 +37,6 @@ static void make_inh_translation_list(Relation oldrelation,
3837
List**translated_vars);
3938
staticNode*adjust_appendrel_attrs_mutator(Node*node,
4039
adjust_appendrel_attrs_context*context);
41-
staticRelidsadjust_child_relids(Relidsrelids,intnappinfos,
42-
AppendRelInfo**appinfos);
4340
staticList*adjust_inherited_tlist(List*tlist,
4441
AppendRelInfo*context);
4542

@@ -166,58 +163,6 @@ make_inh_translation_list(Relation oldrelation, Relation newrelation,
166163
*translated_vars=vars;
167164
}
168165

169-
/*
170-
* translate_col_privs
171-
* Translate a bitmapset representing per-column privileges from the
172-
* parent rel's attribute numbering to the child's.
173-
*
174-
* The only surprise here is that we don't translate a parent whole-row
175-
* reference into a child whole-row reference. That would mean requiring
176-
* permissions on all child columns, which is overly strict, since the
177-
* query is really only going to reference the inherited columns. Instead
178-
* we set the per-column bits for all inherited columns.
179-
*/
180-
Bitmapset*
181-
translate_col_privs(constBitmapset*parent_privs,
182-
List*translated_vars)
183-
{
184-
Bitmapset*child_privs=NULL;
185-
boolwhole_row;
186-
intattno;
187-
ListCell*lc;
188-
189-
/* System attributes have the same numbers in all tables */
190-
for (attno=FirstLowInvalidHeapAttributeNumber+1;attno<0;attno++)
191-
{
192-
if (bms_is_member(attno-FirstLowInvalidHeapAttributeNumber,
193-
parent_privs))
194-
child_privs=bms_add_member(child_privs,
195-
attno-FirstLowInvalidHeapAttributeNumber);
196-
}
197-
198-
/* Check if parent has whole-row reference */
199-
whole_row=bms_is_member(InvalidAttrNumber-FirstLowInvalidHeapAttributeNumber,
200-
parent_privs);
201-
202-
/* And now translate the regular user attributes, using the vars list */
203-
attno=InvalidAttrNumber;
204-
foreach(lc,translated_vars)
205-
{
206-
Var*var=lfirst_node(Var,lc);
207-
208-
attno++;
209-
if (var==NULL)/* ignore dropped columns */
210-
continue;
211-
if (whole_row||
212-
bms_is_member(attno-FirstLowInvalidHeapAttributeNumber,
213-
parent_privs))
214-
child_privs=bms_add_member(child_privs,
215-
var->varattno-FirstLowInvalidHeapAttributeNumber);
216-
}
217-
218-
returnchild_privs;
219-
}
220-
221166
/*
222167
* adjust_appendrel_attrs
223168
* Copy the specified query or expression and translate Vars referring to a
@@ -527,11 +472,53 @@ adjust_appendrel_attrs_mutator(Node *node,
527472
(void*)context);
528473
}
529474

475+
/*
476+
* adjust_appendrel_attrs_multilevel
477+
* Apply Var translations from a toplevel appendrel parent down to a child.
478+
*
479+
* In some cases we need to translate expressions referencing a parent relation
480+
* to reference an appendrel child that's multiple levels removed from it.
481+
*/
482+
Node*
483+
adjust_appendrel_attrs_multilevel(PlannerInfo*root,Node*node,
484+
Relidschild_relids,
485+
Relidstop_parent_relids)
486+
{
487+
AppendRelInfo**appinfos;
488+
Bitmapset*parent_relids=NULL;
489+
intnappinfos;
490+
intcnt;
491+
492+
Assert(bms_num_members(child_relids)==bms_num_members(top_parent_relids));
493+
494+
appinfos=find_appinfos_by_relids(root,child_relids,&nappinfos);
495+
496+
/* Construct relids set for the immediate parent of given child. */
497+
for (cnt=0;cnt<nappinfos;cnt++)
498+
{
499+
AppendRelInfo*appinfo=appinfos[cnt];
500+
501+
parent_relids=bms_add_member(parent_relids,appinfo->parent_relid);
502+
}
503+
504+
/* Recurse if immediate parent is not the top parent. */
505+
if (!bms_equal(parent_relids,top_parent_relids))
506+
node=adjust_appendrel_attrs_multilevel(root,node,parent_relids,
507+
top_parent_relids);
508+
509+
/* Now translate for this child */
510+
node=adjust_appendrel_attrs(root,node,nappinfos,appinfos);
511+
512+
pfree(appinfos);
513+
514+
returnnode;
515+
}
516+
530517
/*
531518
* Substitute child relids for parent relids in a Relid set. The array of
532519
* appinfos specifies the substitutions to be performed.
533520
*/
534-
staticRelids
521+
Relids
535522
adjust_child_relids(Relidsrelids,intnappinfos,AppendRelInfo**appinfos)
536523
{
537524
Bitmapset*result=NULL;
@@ -711,90 +698,6 @@ adjust_inherited_tlist(List *tlist, AppendRelInfo *context)
711698
returnnew_tlist;
712699
}
713700

714-
/*
715-
* adjust_appendrel_attrs_multilevel
716-
* Apply Var translations from a toplevel appendrel parent down to a child.
717-
*
718-
* In some cases we need to translate expressions referencing a parent relation
719-
* to reference an appendrel child that's multiple levels removed from it.
720-
*/
721-
Node*
722-
adjust_appendrel_attrs_multilevel(PlannerInfo*root,Node*node,
723-
Relidschild_relids,
724-
Relidstop_parent_relids)
725-
{
726-
AppendRelInfo**appinfos;
727-
Bitmapset*parent_relids=NULL;
728-
intnappinfos;
729-
intcnt;
730-
731-
Assert(bms_num_members(child_relids)==bms_num_members(top_parent_relids));
732-
733-
appinfos=find_appinfos_by_relids(root,child_relids,&nappinfos);
734-
735-
/* Construct relids set for the immediate parent of given child. */
736-
for (cnt=0;cnt<nappinfos;cnt++)
737-
{
738-
AppendRelInfo*appinfo=appinfos[cnt];
739-
740-
parent_relids=bms_add_member(parent_relids,appinfo->parent_relid);
741-
}
742-
743-
/* Recurse if immediate parent is not the top parent. */
744-
if (!bms_equal(parent_relids,top_parent_relids))
745-
node=adjust_appendrel_attrs_multilevel(root,node,parent_relids,
746-
top_parent_relids);
747-
748-
/* Now translate for this child */
749-
node=adjust_appendrel_attrs(root,node,nappinfos,appinfos);
750-
751-
pfree(appinfos);
752-
753-
returnnode;
754-
}
755-
756-
/*
757-
* Construct the SpecialJoinInfo for a child-join by translating
758-
* SpecialJoinInfo for the join between parents. left_relids and right_relids
759-
* are the relids of left and right side of the join respectively.
760-
*/
761-
SpecialJoinInfo*
762-
build_child_join_sjinfo(PlannerInfo*root,SpecialJoinInfo*parent_sjinfo,
763-
Relidsleft_relids,Relidsright_relids)
764-
{
765-
SpecialJoinInfo*sjinfo=makeNode(SpecialJoinInfo);
766-
AppendRelInfo**left_appinfos;
767-
intleft_nappinfos;
768-
AppendRelInfo**right_appinfos;
769-
intright_nappinfos;
770-
771-
memcpy(sjinfo,parent_sjinfo,sizeof(SpecialJoinInfo));
772-
left_appinfos=find_appinfos_by_relids(root,left_relids,
773-
&left_nappinfos);
774-
right_appinfos=find_appinfos_by_relids(root,right_relids,
775-
&right_nappinfos);
776-
777-
sjinfo->min_lefthand=adjust_child_relids(sjinfo->min_lefthand,
778-
left_nappinfos,left_appinfos);
779-
sjinfo->min_righthand=adjust_child_relids(sjinfo->min_righthand,
780-
right_nappinfos,
781-
right_appinfos);
782-
sjinfo->syn_lefthand=adjust_child_relids(sjinfo->syn_lefthand,
783-
left_nappinfos,left_appinfos);
784-
sjinfo->syn_righthand=adjust_child_relids(sjinfo->syn_righthand,
785-
right_nappinfos,
786-
right_appinfos);
787-
sjinfo->semi_rhs_exprs= (List*)adjust_appendrel_attrs(root,
788-
(Node*)sjinfo->semi_rhs_exprs,
789-
right_nappinfos,
790-
right_appinfos);
791-
792-
pfree(left_appinfos);
793-
pfree(right_appinfos);
794-
795-
returnsjinfo;
796-
}
797-
798701
/*
799702
* find_appinfos_by_relids
800703
* Find AppendRelInfo structures for all relations specified by relids.

‎src/backend/optimizer/util/inherit.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include"postgres.h"
1616

1717
#include"access/heapam.h"
18+
#include"access/sysattr.h"
1819
#include"catalog/partition.h"
1920
#include"catalog/pg_inherits.h"
2021
#include"miscadmin.h"
@@ -38,6 +39,8 @@ static void expand_single_inheritance_child(PlannerInfo *root,
3839
PlanRowMark*top_parentrc,Relationchildrel,
3940
List**appinfos,RangeTblEntry**childrte_p,
4041
Index*childRTindex_p);
42+
staticBitmapset*translate_col_privs(constBitmapset*parent_privs,
43+
List*translated_vars);
4144

4245

4346
/*
@@ -437,3 +440,55 @@ expand_single_inheritance_child(PlannerInfo *root, RangeTblEntry *parentrte,
437440
root->rowMarks=lappend(root->rowMarks,childrc);
438441
}
439442
}
443+
444+
/*
445+
* translate_col_privs
446+
* Translate a bitmapset representing per-column privileges from the
447+
* parent rel's attribute numbering to the child's.
448+
*
449+
* The only surprise here is that we don't translate a parent whole-row
450+
* reference into a child whole-row reference. That would mean requiring
451+
* permissions on all child columns, which is overly strict, since the
452+
* query is really only going to reference the inherited columns. Instead
453+
* we set the per-column bits for all inherited columns.
454+
*/
455+
staticBitmapset*
456+
translate_col_privs(constBitmapset*parent_privs,
457+
List*translated_vars)
458+
{
459+
Bitmapset*child_privs=NULL;
460+
boolwhole_row;
461+
intattno;
462+
ListCell*lc;
463+
464+
/* System attributes have the same numbers in all tables */
465+
for (attno=FirstLowInvalidHeapAttributeNumber+1;attno<0;attno++)
466+
{
467+
if (bms_is_member(attno-FirstLowInvalidHeapAttributeNumber,
468+
parent_privs))
469+
child_privs=bms_add_member(child_privs,
470+
attno-FirstLowInvalidHeapAttributeNumber);
471+
}
472+
473+
/* Check if parent has whole-row reference */
474+
whole_row=bms_is_member(InvalidAttrNumber-FirstLowInvalidHeapAttributeNumber,
475+
parent_privs);
476+
477+
/* And now translate the regular user attributes, using the vars list */
478+
attno=InvalidAttrNumber;
479+
foreach(lc,translated_vars)
480+
{
481+
Var*var=lfirst_node(Var,lc);
482+
483+
attno++;
484+
if (var==NULL)/* ignore dropped columns */
485+
continue;
486+
if (whole_row||
487+
bms_is_member(attno-FirstLowInvalidHeapAttributeNumber,
488+
parent_privs))
489+
child_privs=bms_add_member(child_privs,
490+
var->varattno-FirstLowInvalidHeapAttributeNumber);
491+
}
492+
493+
returnchild_privs;
494+
}

‎src/include/optimizer/appendinfo.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,16 @@
2020
externAppendRelInfo*make_append_rel_info(Relationparentrel,
2121
Relationchildrel,
2222
IndexparentRTindex,IndexchildRTindex);
23-
externBitmapset*translate_col_privs(constBitmapset*parent_privs,
24-
List*translated_vars);
2523
externNode*adjust_appendrel_attrs(PlannerInfo*root,Node*node,
2624
intnappinfos,AppendRelInfo**appinfos);
27-
2825
externNode*adjust_appendrel_attrs_multilevel(PlannerInfo*root,Node*node,
2926
Relidschild_relids,
3027
Relidstop_parent_relids);
31-
32-
externAppendRelInfo**find_appinfos_by_relids(PlannerInfo*root,
33-
Relidsrelids,int*nappinfos);
34-
35-
externSpecialJoinInfo*build_child_join_sjinfo(PlannerInfo*root,
36-
SpecialJoinInfo*parent_sjinfo,
37-
Relidsleft_relids,Relidsright_relids);
28+
externRelidsadjust_child_relids(Relidsrelids,intnappinfos,
29+
AppendRelInfo**appinfos);
3830
externRelidsadjust_child_relids_multilevel(PlannerInfo*root,Relidsrelids,
3931
Relidschild_relids,Relidstop_parent_relids);
32+
externAppendRelInfo**find_appinfos_by_relids(PlannerInfo*root,
33+
Relidsrelids,int*nappinfos);
4034

4135
#endif/* APPENDINFO_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp