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

Commitbfa56c9

Browse files
committed
introduce inline function PrelExpressionForRelid()
1 parent68aea8d commitbfa56c9

File tree

10 files changed

+66
-83
lines changed

10 files changed

+66
-83
lines changed

‎src/hooks.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
130130
}
131131

132132
/* Make copy of partitioning expression and fix Var's varno attributes */
133-
expr=inner_prel->expr;
134-
if (innerrel->relid!=1)
135-
{
136-
expr=copyObject(expr);
137-
ChangeVarNodes(expr,1,innerrel->relid,0);
138-
}
133+
expr=PrelExpressionForRelid(inner_prel,innerrel->relid);
139134

140135
paramsel=1.0;
141136
foreach (lc,joinclauses)
@@ -196,9 +191,9 @@ pathman_join_pathlist_hook(PlannerInfo *root,
196191
innerrel->ppilist=saved_ppi_list;
197192

198193
/* Skip ppi->ppi_clauses don't reference partition attribute */
199-
if (!(ppi&&get_partitioned_attr_clauses(ppi->ppi_clauses,
200-
inner_prel,
201-
innerrel->relid)))
194+
if (!(ppi&&get_partitioning_clauses(ppi->ppi_clauses,
195+
inner_prel,
196+
innerrel->relid)))
202197
continue;
203198

204199
inner=create_runtimeappend_path(root,cur_inner_path,ppi,paramsel);
@@ -319,9 +314,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
319314
boolmodify_append_nodes;
320315

321316
/* Make copy of partitioning expression and fix Var's varno attributes */
322-
expr=copyObject(prel->expr);
323-
if (rti!=1)
324-
ChangeVarNodes(expr,1,rti,0);
317+
expr=PrelExpressionForRelid(prel,rti);
325318

326319
if (prel->parttype==PT_RANGE)
327320
{

‎src/include/nodes_common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ clear_plan_states(CustomScanState *scan_state)
6565
}
6666
}
6767

68-
List*get_partitioned_attr_clauses(List*restrictinfo_list,
69-
constPartRelationInfo*prel,
70-
Indexpartitioned_rel);
68+
List*get_partitioning_clauses(List*restrictinfo_list,
69+
constPartRelationInfo*prel,
70+
Indexpartitioned_rel);
7171

7272
Oid*get_partition_oids(List*ranges,int*n,constPartRelationInfo*prel,
7373
boolinclude_parent);

‎src/include/relation_info.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include"nodes/primnodes.h"
2222
#include"nodes/value.h"
2323
#include"port/atomics.h"
24+
#include"rewrite/rewriteManip.h"
2425
#include"storage/lock.h"
2526
#include"utils/datum.h"
2627
#include"utils/lsyscache.h"
@@ -207,7 +208,7 @@ typedef enum
207208

208209

209210
/*
210-
* PartRelationInfo field access macros.
211+
* PartRelationInfo field access macros & functions.
211212
*/
212213

213214
#definePrelParentRelid(prel)( (prel)->key )
@@ -249,6 +250,21 @@ PrelExpressionColumnNames(const PartRelationInfo *prel)
249250
returncolumns;
250251
}
251252

253+
staticinlineNode*
254+
PrelExpressionForRelid(constPartRelationInfo*prel,Indexrel_index)
255+
{
256+
Node*expr;
257+
258+
if (rel_index!=PART_EXPR_VARNO)
259+
{
260+
expr=copyObject(prel->expr);
261+
ChangeVarNodes(expr,PART_EXPR_VARNO,rel_index,0);
262+
}
263+
elseexpr=prel->expr;
264+
265+
returnexpr;
266+
}
267+
252268

253269
constPartRelationInfo*refresh_pathman_relation_info(Oidrelid,
254270
Datum*values,

‎src/include/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
boolclause_contains_params(Node*clause);
2525
boolis_date_type_internal(Oidtypid);
2626
boolcheck_security_policy_internal(Oidrelid,Oidrole);
27-
boolexpr_matches_operand(Node*operand,Node*expr);
27+
boolmatch_expr_to_operand(Node*expr,Node*operand);
2828

2929
/*
3030
* Misc.

‎src/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ validate_hash_constraint(const Expr *expr,
11091109
hash_arg= (Node*)linitial(type_hash_proc_expr->args);
11101110

11111111
/* Check arg of TYPE_HASH_PROC() */
1112-
if (!expr_matches_operand(prel->expr,hash_arg))
1112+
if (!match_expr_to_operand(prel->expr,hash_arg))
11131113
return false;
11141114

11151115
/* Check that PARTITIONS_COUNT is equal to total amount of partitions */

‎src/nodes_common.c

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -315,65 +315,41 @@ unpack_runtimeappend_private(RuntimeAppendState *scan_state, CustomScan *cscan)
315315
scan_state->enable_parent= (bool)linitial_int(lthird(runtimeappend_private));
316316
}
317317

318-
structcheck_clause_context
319-
{
320-
Node*prel_expr;
321-
intcount;
322-
};
323318

324319
/* Check that one of arguments of OpExpr is expression */
325320
staticbool
326-
check_clause_for_expression(Node*node,structcheck_clause_context*ctx)
321+
clause_contains_prel_expr(Node*node,Node*prel_expr)
327322
{
328323
if (node==NULL)
329324
return false;
330325

331-
if (IsA(node,OpExpr))
332-
{
333-
OpExpr*expr= (OpExpr*)node;
334-
Node*left=linitial(expr->args),
335-
*right=lsecond(expr->args);
336-
337-
if (expr_matches_operand(left,ctx->prel_expr))
338-
ctx->count+=1;
339-
340-
if (expr_matches_operand(right,ctx->prel_expr))
341-
ctx->count+=1;
342-
343-
return false;
344-
}
326+
if (match_expr_to_operand(node,prel_expr))
327+
return true;
345328

346-
returnexpression_tree_walker(node,check_clause_for_expression, (void*)ctx);
329+
returnexpression_tree_walker(node,clause_contains_prel_expr,prel_expr);
347330
}
348331

349332
/*
350333
* Filter all available clauses and extract relevant ones.
351334
*/
352335
List*
353-
get_partitioned_attr_clauses(List*restrictinfo_list,
354-
constPartRelationInfo*prel,
355-
Indexpartitioned_rel)
336+
get_partitioning_clauses(List*restrictinfo_list,
337+
constPartRelationInfo*prel,
338+
Indexpartitioned_rel)
356339
{
357340
List*result=NIL;
358341
ListCell*l;
359342

360343
foreach(l,restrictinfo_list)
361344
{
362-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(l);
363-
structcheck_clause_contextctx;
345+
RestrictInfo*rinfo= (RestrictInfo*)lfirst(l);
346+
Node*prel_expr;
364347

365348
Assert(IsA(rinfo,RestrictInfo));
366349

367-
ctx.count=0;
368-
ctx.prel_expr=prel->expr;
369-
if (partitioned_rel!=1)
370-
{
371-
ctx.prel_expr=copyObject(prel->expr);
372-
ChangeVarNodes(ctx.prel_expr,1,partitioned_rel,0);
373-
}
374-
check_clause_for_expression((Node*)rinfo->clause,&ctx);
350+
prel_expr=PrelExpressionForRelid(prel,partitioned_rel);
375351

376-
if (ctx.count==1)
352+
if (clause_contains_prel_expr((Node*)rinfo->clause,prel_expr))
377353
result=lappend(result,rinfo->clause);
378354
}
379355
returnresult;
@@ -591,7 +567,7 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
591567
/* Since we're not scanning any real table directly */
592568
cscan->scan.scanrelid=0;
593569

594-
cscan->custom_exprs=get_partitioned_attr_clauses(clauses,prel,rel->relid);
570+
cscan->custom_exprs=get_partitioning_clauses(clauses,prel,rel->relid);
595571
cscan->custom_plans=custom_plans;
596572
cscan->methods=scan_methods;
597573

‎src/partition_filter.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ select_partition_for_insert(Datum value, Oid value_type,
417417
ResultPartsStorage*parts_storage,
418418
EState*estate)
419419
{
420-
MemoryContextold_cxt;
420+
MemoryContextold_mcxt;
421421
ResultRelInfoHolder*rri_holder;
422422
Oidselected_partid=InvalidOid;
423423
Oid*parts;
@@ -439,9 +439,9 @@ select_partition_for_insert(Datum value, Oid value_type,
439439
elseselected_partid=parts[0];
440440

441441
/* Replace parent table with a suitable partition */
442-
old_cxt=MemoryContextSwitchTo(estate->es_query_cxt);
442+
old_mcxt=MemoryContextSwitchTo(estate->es_query_cxt);
443443
rri_holder=scan_result_parts_storage(selected_partid,parts_storage);
444-
MemoryContextSwitchTo(old_cxt);
444+
MemoryContextSwitchTo(old_mcxt);
445445

446446
/* Could not find suitable partition */
447447
if (rri_holder==NULL)
@@ -531,12 +531,12 @@ partition_filter_create_scan_state(CustomScan *node)
531531
void
532532
partition_filter_begin(CustomScanState*node,EState*estate,inteflags)
533533
{
534-
Indexvarno=1;
535-
Node*expr;
536-
MemoryContextold_cxt;
537-
PartitionFilterState*state= (PartitionFilterState*)node;
538-
constPartRelationInfo*prel;
539-
ListCell*lc;
534+
Indexvarno=1;
535+
Node*expr;
536+
MemoryContextold_mcxt;
537+
PartitionFilterState*state= (PartitionFilterState*)node;
538+
constPartRelationInfo*prel;
539+
ListCell*lc;
540540

541541
/* It's convenient to store PlanState in 'custom_ps' */
542542
node->custom_ps=list_make1(ExecInitNode(state->subplan,estate,eflags));
@@ -562,9 +562,9 @@ partition_filter_begin(CustomScanState *node, EState *estate, int eflags)
562562
}
563563

564564
/* Prepare state for expression execution */
565-
old_cxt=MemoryContextSwitchTo(estate->es_query_cxt);
565+
old_mcxt=MemoryContextSwitchTo(estate->es_query_cxt);
566566
state->expr_state=ExecInitExpr((Expr*)expr,NULL);
567-
MemoryContextSwitchTo(old_cxt);
567+
MemoryContextSwitchTo(old_mcxt);
568568
}
569569

570570
/* Init ResultRelInfo cache */
@@ -595,13 +595,13 @@ partition_filter_exec(CustomScanState *node)
595595

596596
if (!TupIsNull(slot))
597597
{
598-
MemoryContextold_cxt;
599-
constPartRelationInfo*prel;
600-
ResultRelInfoHolder*rri_holder;
601-
boolisnull;
602-
Datumvalue;
603-
ExprDoneConditemIsDone;
604-
TupleTableSlot*tmp_slot;
598+
MemoryContextold_mcxt;
599+
constPartRelationInfo*prel;
600+
ResultRelInfoHolder*rri_holder;
601+
boolisnull;
602+
Datumvalue;
603+
ExprDoneConditemIsDone;
604+
TupleTableSlot*tmp_slot;
605605

606606
/* Fetch PartRelationInfo for this partitioned relation */
607607
prel=get_pathman_relation_info(state->partitioned_table);
@@ -616,7 +616,7 @@ partition_filter_exec(CustomScanState *node)
616616
}
617617

618618
/* Switch to per-tuple context */
619-
old_cxt=MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
619+
old_mcxt=MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
620620

621621
/* Execute expression */
622622
tmp_slot=econtext->ecxt_scantuple;
@@ -635,7 +635,7 @@ partition_filter_exec(CustomScanState *node)
635635
&state->result_parts,estate);
636636

637637
/* Switch back and clean up per-tuple context */
638-
MemoryContextSwitchTo(old_cxt);
638+
MemoryContextSwitchTo(old_mcxt);
639639
ResetExprContext(econtext);
640640

641641
/* Magic: replace parent's ResultRelInfo with ours */

‎src/pg_pathman.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ handle_arrexpr(const ScalarArrayOpExpr *expr, WalkerContext *context)
867867

868868
Assert(exprnode!=NULL);
869869

870-
if (!expr_matches_operand(context->prel_expr,exprnode))
870+
if (!match_expr_to_operand(context->prel_expr,exprnode))
871871
gotohandle_arrexpr_return;
872872

873873
if (arraynode&&IsA(arraynode,Const)&&
@@ -1145,14 +1145,14 @@ pull_var_param(const WalkerContext *ctx,
11451145
Node*left=linitial(expr->args),
11461146
*right=lsecond(expr->args);
11471147

1148-
if (expr_matches_operand(left,ctx->prel_expr))
1148+
if (match_expr_to_operand(left,ctx->prel_expr))
11491149
{
11501150
*var_ptr=left;
11511151
*param_ptr=right;
11521152
return true;
11531153
}
11541154

1155-
if (expr_matches_operand(right,ctx->prel_expr))
1155+
if (match_expr_to_operand(right,ctx->prel_expr))
11561156
{
11571157
*var_ptr=right;
11581158
*param_ptr=left;

‎src/planner_tree_modification.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,13 @@ static void
239239
handle_modification_query(Query*parse)
240240
{
241241
constPartRelationInfo*prel;
242+
Node*prel_expr;
242243
List*ranges;
243244
RangeTblEntry*rte;
244245
WrapperNode*wrap;
245246
Expr*expr;
246247
WalkerContextcontext;
247248
Indexresult_rel;
248-
Node*prel_expr;
249249

250250
/* Fetch index of result relation */
251251
result_rel=parse->resultRelation;
@@ -277,9 +277,7 @@ handle_modification_query(Query *parse)
277277
if (!expr)return;
278278

279279
/* Prepare partitioning expression */
280-
prel_expr=copyObject(prel->expr);
281-
if (result_rel!=1)
282-
ChangeVarNodes(prel_expr,1,result_rel,0);
280+
prel_expr=PrelExpressionForRelid(prel,result_rel);
283281

284282
/* Parse syntax tree and extract partition ranges */
285283
InitWalkerContext(&context,prel_expr,prel,NULL, false);

‎src/utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ check_security_policy_internal(Oid relid, Oid role)
108108

109109
/* Compare clause operand with expression */
110110
bool
111-
expr_matches_operand(Node*operand,Node*expr)
111+
match_expr_to_operand(Node*expr,Node*operand)
112112
{
113-
/*strip relabeling for both operand and expr */
113+
/*Strip relabeling for both operand and expr */
114114
if (operand&&IsA(operand,RelabelType))
115115
operand= (Node*) ((RelabelType*)operand)->arg;
116116

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp