Skip to content

Commit e50016d

Browse files
committed
restore function clause_contains_params() and get rid of 'found_params' in WalkerContext
1 parent 34272f3 commit e50016d

File tree

5 files changed

+47
-34
lines changed

5 files changed

+47
-34
lines changed

src/hooks.c

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ pathman_join_pathlist_hook(PlannerInfo *root,
8181
const PartRelationInfo *inner_prel;
8282
List *joinclauses,
8383
*otherclauses;
84-
ListCell *lc;
8584
WalkerContext context;
8685
double paramsel;
87-
Node *expr;
86+
Node *part_expr;
87+
ListCell *lc;
8888

8989
/* Call hooks set by other extensions */
9090
if (set_join_pathlist_next)
@@ -130,14 +130,14 @@ pathman_join_pathlist_hook(PlannerInfo *root,
130130
}
131131

132132
/* Make copy of partitioning expression and fix Var's varno attributes */
133-
expr = PrelExpressionForRelid(inner_prel, innerrel->relid);
133+
part_expr = PrelExpressionForRelid(inner_prel, innerrel->relid);
134134

135135
paramsel = 1.0;
136136
foreach (lc, joinclauses)
137137
{
138138
WrapperNode *wrap;
139139

140-
InitWalkerContext(&context, expr, inner_prel, NULL, false);
140+
InitWalkerContext(&context, part_expr, inner_prel, NULL, false);
141141
wrap = walk_expr_tree((Expr *) lfirst(lc), &context);
142142
paramsel *= wrap->paramsel;
143143
}
@@ -308,13 +308,13 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
308308
*pathkeyDesc = NULL;
309309
double paramsel = 1.0; /* default part selectivity */
310310
WalkerContext context;
311-
Node *expr;
312-
bool modify_append_nodes;
311+
Node *part_expr;
312+
List *part_clauses;
313313
ListCell *lc;
314314
int i;
315315

316316
/* Make copy of partitioning expression and fix Var's varno attributes */
317-
expr = PrelExpressionForRelid(prel, rti);
317+
part_expr = PrelExpressionForRelid(prel, rti);
318318

319319
if (prel->parttype == PT_RANGE)
320320
{
@@ -328,11 +328,11 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
328328
tce = lookup_type_cache(prel->atttype, TYPECACHE_LT_OPR | TYPECACHE_GT_OPR);
329329

330330
/* Make pathkeys */
331-
pathkeys = build_expression_pathkey(root, (Expr *) expr, NULL,
331+
pathkeys = build_expression_pathkey(root, (Expr *) part_expr, NULL,
332332
tce->lt_opr, NULL, false);
333333
if (pathkeys)
334334
pathkeyAsc = (PathKey *) linitial(pathkeys);
335-
pathkeys = build_expression_pathkey(root, (Expr *) expr, NULL,
335+
pathkeys = build_expression_pathkey(root, (Expr *) part_expr, NULL,
336336
tce->gt_opr, NULL, false);
337337
if (pathkeys)
338338
pathkeyDesc = (PathKey *) linitial(pathkeys);
@@ -345,7 +345,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
345345
ranges = list_make1_irange_full(prel, IR_COMPLETE);
346346

347347
/* Make wrappers over restrictions and collect final rangeset */
348-
InitWalkerContext(&context, expr, prel, NULL, false);
348+
InitWalkerContext(&context, part_expr, prel, NULL, false);
349349
wrappers = NIL;
350350
foreach(lc, rel->baserestrictinfo)
351351
{
@@ -359,12 +359,6 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
359359
ranges = irange_list_intersection(ranges, wrap->rangeset);
360360
}
361361

362-
/*
363-
* Walker should been have filled these parameter while checking.
364-
* Runtime[Merge]Append is pointless if there are no params in clauses.
365-
*/
366-
modify_append_nodes = context.found_params;
367-
368362
/* Get number of selected partitions */
369363
irange_len = irange_list_length(ranges);
370364
if (prel->enable_parent)
@@ -441,7 +435,13 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
441435
pg_pathman_enable_runtime_merge_append))
442436
return;
443437

444-
if (!modify_append_nodes)
438+
/* Get partitioning-related clauses */
439+
part_clauses = get_partitioning_clauses(list_union(rel->baserestrictinfo,
440+
rel->joininfo),
441+
prel, rti);
442+
443+
/* Skip if there's no PARAMs in partitioning-related clauses */
444+
if (!clause_contains_params((Node *) part_clauses))
445445
return;
446446

447447
/* Generate Runtime[Merge]Append paths if needed */
@@ -462,12 +462,6 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
462462
/* Get existing parameterization */
463463
ppi = get_appendrel_parampathinfo(rel, inner_required);
464464

465-
/* Skip if there are no partitioning clauses */
466-
if (!get_partitioning_clauses(list_union(rel->baserestrictinfo,
467-
rel->joininfo),
468-
prel, rti))
469-
return;
470-
471465
if (IsA(cur_path, AppendPath) && pg_pathman_enable_runtimeappend)
472466
inner_path = create_runtimeappend_path(root, cur_path,
473467
ppi, paramsel);

src/include/pathman.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ typedef struct
148148
const PartRelationInfo *prel; /* main partitioning structure */
149149
ExprContext *econtext; /* for ExecEvalExpr() */
150150
bool for_insert; /* are we in PartitionFilter now? */
151-
bool found_params; /* mark if left or right argument
152-
of clause is Param */
153151
} WalkerContext;
154152

155153
/* Usual initialization procedure for WalkerContext */
@@ -159,7 +157,6 @@ typedef struct
159157
(context)->prel = (prel_info); \
160158
(context)->econtext = (ecxt); \
161159
(context)->for_insert = (for_ins); \
162-
(context)->found_params = (false); \
163160
} while (0)
164161

165162
/* Check that WalkerContext contains ExprContext (plan execution stage) */

src/nodes_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ clause_contains_prel_expr(Node *node, Node *prel_expr)
323323
if (node == NULL)
324324
return false;
325325

326-
if (match_expr_to_operand(node, prel_expr))
326+
if (match_expr_to_operand(prel_expr, node))
327327
return true;
328328

329329
return expression_tree_walker(node, clause_contains_prel_expr, prel_expr);

src/pg_pathman.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void handle_binary_opexpr_param(const PartRelationInfo *prel,
6565
WrapperNode *result,
6666
const Node *varnode);
6767

68-
static bool pull_var_param(const WalkerContext *ctx,
68+
static bool pull_var_param(const WalkerContext *context,
6969
const OpExpr *expr,
7070
Node **var_ptr,
7171
Node **param_ptr);
@@ -1012,9 +1012,6 @@ handle_opexpr(const OpExpr *expr, WalkerContext *context)
10121012
}
10131013
else if (IsA(param, Param) || IsA(param, Var))
10141014
{
1015-
if (IsA(param, Param))
1016-
context->found_params = true;
1017-
10181015
handle_binary_opexpr_param(prel, result, var);
10191016
return result;
10201017
}
@@ -1140,22 +1137,22 @@ handle_binary_opexpr_param(const PartRelationInfo *prel,
11401137
* NOTE: returns false if partition key is not in expression.
11411138
*/
11421139
static bool
1143-
pull_var_param(const WalkerContext *ctx,
1140+
pull_var_param(const WalkerContext *context,
11441141
const OpExpr *expr,
11451142
Node **var_ptr,
11461143
Node **param_ptr)
11471144
{
11481145
Node *left = linitial(expr->args),
11491146
*right = lsecond(expr->args);
11501147

1151-
if (match_expr_to_operand(left, ctx->prel_expr))
1148+
if (match_expr_to_operand(context->prel_expr, left))
11521149
{
11531150
*var_ptr = left;
11541151
*param_ptr = right;
11551152
return true;
11561153
}
11571154

1158-
if (match_expr_to_operand(right, ctx->prel_expr))
1155+
if (match_expr_to_operand(context->prel_expr, right))
11591156
{
11601157
*var_ptr = right;
11611158
*param_ptr = left;

src/utils.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@
3434
#include "utils/typcache.h"
3535

3636

37+
static bool
38+
clause_contains_params_walker(Node *node, void *context)
39+
{
40+
if (node == NULL)
41+
return false;
42+
43+
if (IsA(node, Param))
44+
return true;
45+
46+
return expression_tree_walker(node,
47+
clause_contains_params_walker,
48+
context);
49+
}
50+
51+
/*
52+
* Check whether clause contains PARAMs or not.
53+
*/
54+
bool
55+
clause_contains_params(Node *clause)
56+
{
57+
return expression_tree_walker(clause,
58+
clause_contains_params_walker,
59+
NULL);
60+
}
61+
3762
/*
3863
* Check if this is a "date"-related type.
3964
*/

0 commit comments

Comments
 (0)