Skip to content

Commit 9828aca

Browse files
committed
add 'prel_varno' to WalkerContext
1 parent 10021fa commit 9828aca

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

src/hooks.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ pathman_join_pathlist_hook(PlannerInfo *root,
9898
{
9999
WrapperNode *wrap;
100100

101-
InitWalkerContext(&context, inner_prel, NULL, false);
101+
InitWalkerContext(&context, innerrel->relid,
102+
inner_prel, NULL, false);
102103

103104
wrap = walk_expr_tree((Expr *) lfirst(lc), &context);
104105
paramsel *= wrap->paramsel;
@@ -266,7 +267,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
266267
ranges = list_make1_irange(make_irange(0, PrelLastChild(prel), false));
267268

268269
/* Make wrappers over restrictions and collect final rangeset */
269-
InitWalkerContext(&context, prel, NULL, false);
270+
InitWalkerContext(&context, rti, prel, NULL, false);
270271
wrappers = NIL;
271272
foreach(lc, rel->baserestrictinfo)
272273
{

src/nodes_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,10 @@ rescan_append_common(CustomScanState *node)
558558
/* First we select all available partitions... */
559559
ranges = list_make1_irange(make_irange(0, PrelLastChild(prel), false));
560560

561-
InitWalkerContext(&wcxt, prel, econtext, false);
561+
InitWalkerContext(&wcxt, INDEX_VAR, prel, econtext, false);
562562
foreach (lc, scan_state->custom_exprs)
563563
{
564-
WrapperNode *wn;
564+
WrapperNode *wn;
565565

566566
/* ... then we cut off irrelevant ones using the provided clauses */
567567
wn = walk_expr_tree((Expr *) lfirst(lc), &wcxt);

src/partition_filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ find_partitions_for_value(Datum value, const PartRelationInfo *prel,
307307
CopyToTempConst(constlen, attlen);
308308
CopyToTempConst(constbyval, attbyval);
309309

310-
InitWalkerContext(&wcxt, prel, econtext, true);
310+
/* We use 0 since varno doesn't matter for Const */
311+
InitWalkerContext(&wcxt, 0, prel, econtext, true);
311312
ranges = walk_expr_tree((Expr *) &temp_const, &wcxt)->rangeset;
312313
return get_partition_oids(ranges, nparts, prel, false);
313314
}

src/pathman.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ typedef struct
140140

141141
typedef struct
142142
{
143+
Index prel_varno; /* Var::varno associated with prel */
143144
const PartRelationInfo *prel; /* main partitioning structure */
144145
ExprContext *econtext; /* for ExecEvalExpr() */
145146
bool for_insert; /* are we in PartitionFilter now? */
@@ -148,8 +149,9 @@ typedef struct
148149
/*
149150
* Usual initialization procedure for WalkerContext.
150151
*/
151-
#define InitWalkerContext(context, prel_info, ecxt, for_ins) \
152+
#define InitWalkerContext(context, prel_vno, prel_info, ecxt, for_ins) \
152153
do { \
154+
(context)->prel_varno = (prel_vno); \
153155
(context)->prel = (prel_info); \
154156
(context)->econtext = (ecxt); \
155157
(context)->for_insert = (for_ins); \

src/pg_pathman.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,9 @@ pull_var_param(const WalkerContext *ctx,
12891289
(Var *) left :
12901290
(Var *) ((RelabelType *) left)->arg;
12911291

1292-
if (v->varoattno == ctx->prel->attnum)
1292+
/* Check if 'v' is partitioned column of 'prel' */
1293+
if (v->varoattno == ctx->prel->attnum &&
1294+
v->varno == ctx->prel_varno)
12931295
{
12941296
*var_ptr = left;
12951297
*param_ptr = right;
@@ -1304,7 +1306,9 @@ pull_var_param(const WalkerContext *ctx,
13041306
(Var *) right :
13051307
(Var *) ((RelabelType *) right)->arg;
13061308

1307-
if (v->varoattno == ctx->prel->attnum)
1309+
/* Check if 'v' is partitioned column of 'prel' */
1310+
if (v->varoattno == ctx->prel->attnum &&
1311+
v->varno == ctx->prel_varno)
13081312
{
13091313
*var_ptr = right;
13101314
*param_ptr = left;
@@ -1409,7 +1413,8 @@ handle_arrexpr(const ScalarArrayOpExpr *expr, WalkerContext *context)
14091413

14101414
/* Skip if base types or attribute numbers do not match */
14111415
if (getBaseType(var->vartype) != getBaseType(prel->atttype) ||
1412-
var->varoattno != prel->attnum)
1416+
var->varoattno != prel->attnum || /* partitioned attribute */
1417+
var->varno != context->prel_varno) /* partitioned table */
14131418
{
14141419
goto handle_arrexpr_return;
14151420
}

src/planner_tree_modification.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,18 @@ handle_modification_query(Query *parse)
289289
WrapperNode *wrap;
290290
Expr *expr;
291291
WalkerContext context;
292+
Index result_rel;
293+
294+
/* Fetch index of result relation */
295+
result_rel = parse->resultRelation;
292296

293297
/* Exit if it's not a DELETE or UPDATE query */
294-
if (parse->resultRelation == 0 ||
298+
if (result_rel == 0 ||
295299
(parse->commandType != CMD_UPDATE &&
296300
parse->commandType != CMD_DELETE))
297301
return;
298302

299-
rte = rt_fetch(parse->resultRelation, parse->rtable);
303+
rte = rt_fetch(result_rel, parse->rtable);
300304
prel = get_pathman_relation_info(rte->relid);
301305

302306
/* Exit if it's not partitioned */
@@ -310,7 +314,7 @@ handle_modification_query(Query *parse)
310314
if (!expr) return;
311315

312316
/* Parse syntax tree and extract partition ranges */
313-
InitWalkerContext(&context, prel, NULL, false);
317+
InitWalkerContext(&context, result_rel, prel, NULL, false);
314318
wrap = walk_expr_tree(expr, &context);
315319

316320
ranges = irange_list_intersect(ranges, wrap->rangeset);

0 commit comments

Comments
 (0)