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

Commitbb060d7

Browse files
author
Alexander Korotkov
committed
Introduce WalkerContext.
1 parent1013500 commitbb060d7

File tree

1 file changed

+53
-38
lines changed

1 file changed

+53
-38
lines changed

‎pg_pathman.c

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ typedef struct
5656
List*rangeset;
5757
}WrapperNode;
5858

59+
typedefstruct
60+
{
61+
constPartRelationInfo*prel;
62+
Datumleast;
63+
Datumgreatest;
64+
}WalkerContext;
65+
5966
boolpg_pathman_enable;
6067
PathmanState*pmstate;
6168

@@ -86,12 +93,12 @@ static void disable_inheritance_subselect(Query *parse);
8693
boolinheritance_disabled;
8794

8895
/* Expression tree handlers */
89-
staticWrapperNode*walk_expr_tree(Expr*expr,constPartRelationInfo*prel);
96+
staticWrapperNode*walk_expr_tree(Expr*expr,WalkerContext*context);
9097
staticintmake_hash(constPartRelationInfo*prel,intvalue);
91-
staticvoidhandle_binary_opexpr(constPartRelationInfo*prel,WrapperNode*result,constVar*v,constConst*c);
92-
staticWrapperNode*handle_opexpr(constOpExpr*expr,constPartRelationInfo*prel);
93-
staticWrapperNode*handle_boolexpr(constBoolExpr*expr,constPartRelationInfo*prel);
94-
staticWrapperNode*handle_arrexpr(constScalarArrayOpExpr*expr,constPartRelationInfo*prel);
98+
staticvoidhandle_binary_opexpr(WalkerContext*context,WrapperNode*result,constVar*v,constConst*c);
99+
staticWrapperNode*handle_opexpr(constOpExpr*expr,WalkerContext*context);
100+
staticWrapperNode*handle_boolexpr(constBoolExpr*expr,WalkerContext*context);
101+
staticWrapperNode*handle_arrexpr(constScalarArrayOpExpr*expr,WalkerContext*context);
95102
staticvoidchange_varnos_in_restrinct_info(RestrictInfo*rinfo,change_varno_context*context);
96103
staticvoidchange_varnos(Node*node,Oidold_varno,Oidnew_varno);
97104
staticboolchange_varno_walker(Node*node,change_varno_context*context);
@@ -359,12 +366,13 @@ disable_inheritance_subselect(Query *parse)
359366
staticvoid
360367
handle_modification_query(Query*parse)
361368
{
362-
PartRelationInfo*prel;
363-
List*ranges;
364-
RangeTblEntry*rte;
365-
WrapperNode*wrap;
366-
Expr*expr;
367-
boolfound;
369+
PartRelationInfo*prel;
370+
List*ranges;
371+
RangeTblEntry*rte;
372+
WrapperNode*wrap;
373+
Expr*expr;
374+
boolfound;
375+
WalkerContextcontext;
368376

369377
Assert(parse->commandType==CMD_UPDATE||
370378
parse->commandType==CMD_DELETE);
@@ -383,7 +391,8 @@ handle_modification_query(Query *parse)
383391
return;
384392

385393
/* Parse syntax tree and extract partition ranges */
386-
wrap=walk_expr_tree(expr,prel);
394+
context.prel=prel;
395+
wrap=walk_expr_tree(expr,&context);
387396
ranges=irange_list_intersect(ranges,wrap->rangeset);
388397

389398
/* If only one partition is affected then substitute parent table with partition */
@@ -424,11 +433,11 @@ pathman_shmem_startup(void)
424433
void
425434
pathman_set_rel_pathlist_hook(PlannerInfo*root,RelOptInfo*rel,Indexrti,RangeTblEntry*rte)
426435
{
427-
PartRelationInfo*prel=NULL;
428-
RelOptInfo**new_rel_array;
429-
RangeTblEntry**new_rte_array;
430-
intlen;
431-
boolfound;
436+
PartRelationInfo*prel=NULL;
437+
RelOptInfo**new_rel_array;
438+
RangeTblEntry**new_rte_array;
439+
intlen;
440+
boolfound;
432441

433442
/* Invoke original hook if needed */
434443
if (set_rel_pathlist_hook_original!=NULL)
@@ -497,11 +506,13 @@ pathman_set_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, Ran
497506
wrappers=NIL;
498507
foreach(lc,rel->baserestrictinfo)
499508
{
500-
WrapperNode*wrap;
509+
WrapperNode*wrap;
510+
WalkerContextcontext;
501511

502512
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
503513

504-
wrap=walk_expr_tree(rinfo->clause,prel);
514+
context.prel=prel;
515+
wrap=walk_expr_tree(rinfo->clause,&context);
505516
wrappers=lappend(wrappers,wrap);
506517
ranges=irange_list_intersect(ranges,wrap->rangeset);
507518
}
@@ -523,11 +534,11 @@ pathman_set_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, Ran
523534
palloc0((root->simple_rel_array_size+len)*sizeof(RangeTblEntry*));
524535

525536
/* Copy relations to the new arrays */
526-
for (i=0;i<root->simple_rel_array_size;i++)
527-
{
528-
new_rel_array[i]=root->simple_rel_array[i];
529-
new_rte_array[i]=root->simple_rte_array[i];
530-
}
537+
for (i=0;i<root->simple_rel_array_size;i++)
538+
{
539+
new_rel_array[i]=root->simple_rel_array[i];
540+
new_rte_array[i]=root->simple_rte_array[i];
541+
}
531542

532543
/* Free old arrays */
533544
pfree(root->simple_rel_array);
@@ -564,8 +575,8 @@ static void
564575
set_append_rel_size(PlannerInfo*root,RelOptInfo*rel,
565576
Indexrti,RangeTblEntry*rte)
566577
{
567-
doubleparent_rows=0;
568-
doubleparent_size=0;
578+
doubleparent_rows=0;
579+
doubleparent_size=0;
569580
ListCell*l;
570581

571582
foreach(l,root->append_rel_list)
@@ -943,7 +954,7 @@ change_varnos_in_restrinct_info(RestrictInfo *rinfo, change_varno_context *conte
943954
* Recursive function to walk through conditions tree
944955
*/
945956
staticWrapperNode*
946-
walk_expr_tree(Expr*expr,constPartRelationInfo*prel)
957+
walk_expr_tree(Expr*expr,WalkerContext*context)
947958
{
948959
BoolExpr*boolexpr;
949960
OpExpr*opexpr;
@@ -955,20 +966,20 @@ walk_expr_tree(Expr *expr, const PartRelationInfo *prel)
955966
/* AND, OR, NOT expressions */
956967
caseT_BoolExpr:
957968
boolexpr= (BoolExpr*)expr;
958-
returnhandle_boolexpr(boolexpr,prel);
969+
returnhandle_boolexpr(boolexpr,context);
959970
/* =, !=, <, > etc. */
960971
caseT_OpExpr:
961972
opexpr= (OpExpr*)expr;
962-
returnhandle_opexpr(opexpr,prel);
973+
returnhandle_opexpr(opexpr,context);
963974
/* IN expression */
964975
caseT_ScalarArrayOpExpr:
965976
arrexpr= (ScalarArrayOpExpr*)expr;
966-
returnhandle_arrexpr(arrexpr,prel);
977+
returnhandle_arrexpr(arrexpr,context);
967978
default:
968979
result= (WrapperNode*)palloc(sizeof(WrapperNode));
969980
result->orig= (constNode*)expr;
970981
result->args=NIL;
971-
result->rangeset=list_make1_irange(make_irange(0,prel->children_count-1, true));
982+
result->rangeset=list_make1_irange(make_irange(0,context->prel->children_count-1, true));
972983
returnresult;
973984
}
974985
}
@@ -977,7 +988,7 @@ walk_expr_tree(Expr *expr, const PartRelationInfo *prel)
977988
*This function determines which partitions should appear in query plan
978989
*/
979990
staticvoid
980-
handle_binary_opexpr(constPartRelationInfo*prel,WrapperNode*result,
991+
handle_binary_opexpr(WalkerContext*context,WrapperNode*result,
981992
constVar*v,constConst*c)
982993
{
983994
HashRelationKeykey;
@@ -992,6 +1003,7 @@ handle_binary_opexpr(const PartRelationInfo *prel, WrapperNode *result,
9921003
Oidcmp_proc_oid;
9931004
constOpExpr*expr= (constOpExpr*)result->orig;
9941005
TypeCacheEntry*tce;
1006+
constPartRelationInfo*prel=context->prel;
9951007

9961008
/* Determine operator type */
9971009
tce=lookup_type_cache(v->vartype,
@@ -1240,11 +1252,12 @@ range_binary_search(const RangeRelation *rangerel, FmgrInfo *cmp_func, Datum val
12401252
* Operator expression handler
12411253
*/
12421254
staticWrapperNode*
1243-
handle_opexpr(constOpExpr*expr,constPartRelationInfo*prel)
1255+
handle_opexpr(constOpExpr*expr,WalkerContext*context)
12441256
{
12451257
WrapperNode*result= (WrapperNode*)palloc(sizeof(WrapperNode));
12461258
Node*firstarg=NULL,
12471259
*secondarg=NULL;
1260+
constPartRelationInfo*prel=context->prel;
12481261

12491262
result->orig= (constNode*)expr;
12501263
result->args=NIL;
@@ -1257,13 +1270,13 @@ handle_opexpr(const OpExpr *expr, const PartRelationInfo *prel)
12571270
if (IsA(firstarg,Var)&&IsA(secondarg,Const)&&
12581271
((Var*)firstarg)->varattno==prel->attnum)
12591272
{
1260-
handle_binary_opexpr(prel,result, (Var*)firstarg, (Const*)secondarg);
1273+
handle_binary_opexpr(context,result, (Var*)firstarg, (Const*)secondarg);
12611274
returnresult;
12621275
}
12631276
elseif (IsA(secondarg,Var)&&IsA(firstarg,Const)&&
12641277
((Var*)secondarg)->varattno==prel->attnum)
12651278
{
1266-
handle_binary_opexpr(prel,result, (Var*)secondarg, (Const*)firstarg);
1279+
handle_binary_opexpr(context,result, (Var*)secondarg, (Const*)firstarg);
12671280
returnresult;
12681281
}
12691282
}
@@ -1276,10 +1289,11 @@ handle_opexpr(const OpExpr *expr, const PartRelationInfo *prel)
12761289
* Boolean expression handler
12771290
*/
12781291
staticWrapperNode*
1279-
handle_boolexpr(constBoolExpr*expr,constPartRelationInfo*prel)
1292+
handle_boolexpr(constBoolExpr*expr,WalkerContext*context)
12801293
{
12811294
WrapperNode*result= (WrapperNode*)palloc(sizeof(WrapperNode));
12821295
ListCell*lc;
1296+
constPartRelationInfo*prel=context->prel;
12831297

12841298
result->orig= (constNode*)expr;
12851299
result->args=NIL;
@@ -1293,7 +1307,7 @@ handle_boolexpr(const BoolExpr *expr, const PartRelationInfo *prel)
12931307
{
12941308
WrapperNode*arg;
12951309

1296-
arg=walk_expr_tree((Expr*)lfirst(lc),prel);
1310+
arg=walk_expr_tree((Expr*)lfirst(lc),context);
12971311
result->args=lappend(result->args,arg);
12981312
switch(expr->boolop)
12991313
{
@@ -1316,12 +1330,13 @@ handle_boolexpr(const BoolExpr *expr, const PartRelationInfo *prel)
13161330
* Scalar array expression
13171331
*/
13181332
staticWrapperNode*
1319-
handle_arrexpr(constScalarArrayOpExpr*expr,constPartRelationInfo*prel)
1333+
handle_arrexpr(constScalarArrayOpExpr*expr,WalkerContext*context)
13201334
{
13211335
WrapperNode*result= (WrapperNode*)palloc(sizeof(WrapperNode));
13221336
Node*varnode= (Node*)linitial(expr->args);
13231337
Node*arraynode= (Node*)lsecond(expr->args);
13241338
inthash;
1339+
constPartRelationInfo*prel=context->prel;
13251340

13261341
result->orig= (constNode*)expr;
13271342
result->args=NIL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp