8000 Fix runtime partition pruning for HASH partitioned tables · postgres/postgres@2759924 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2759924

Browse files
committed
Fix runtime partition pruning for HASH partitioned tables
This could only affect HASH partitioned tables with at least 2 partition key columns. If partition pruning was delayed until execution and the query contained an IS NULL qual on one of the partitioned keys, and some subsequent partitioned key was being compared to a non-Const, then this could result in a crash due to the incorrect keyno being used to calculate the stateidx for the expression evaluation code. Here we fix this by properly skipping partitioned keys which have a nullkey set. Effectively, this must be the same as what's going on inside perform_pruning_base_step(). Sergei Glukhov also provided a patch, but that's not what's being used here. Reported-by: Sergei Glukhov Reviewed-by: tender wang, Sergei Glukhov Discussion: https://postgr.es/m/d05b26fa-af54-27e1-f693-6c31590802fa@postgrespro.ru Backpatch-through: 11, where runtime partition pruning was added.
1 parent 8f1d44b commit 2759924

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/backend/executor/execPartition.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ ExecInitPruningContext(PartitionPruneContext *context,
16731673
foreach(lc, pruning_steps)
16741674
{
16751675
PartitionPruneStepOp *step = (PartitionPruneStepOp *) lfirst(lc);
1676-
ListCell *lc2;
1676+
ListCell *lc2 = list_head(step->exprs);
16771677
int keyno;
16781678

16791679
/* not needed for other step kinds */
@@ -1682,22 +1682,27 @@ ExecInitPruningContext(PartitionPruneContext *context,
16821682

16831683
Assert(list_length(step->exprs) <= partnatts);
16841684

1685-
keyno = 0;
1686-
foreach(lc2, step->exprs)
1685+
for (keyno = 0; keyno < partnatts; keyno++)
16871686
{
1688-
Expr *expr = (Expr *) lfirst(lc2);
1687+
if (bms_is_member(keyno, step->nullkeys))
1688+
continue;
16891689

1690-
/* not needed for Consts */
1691-
if (!IsA(expr, Const))
1690+
if (lc2 != NULL)
16921691
{
1693-
int stateidx = PruneCxtStateIdx(partnatts,
1694-
step->step.step_id,
1695-
keyno);
1692+
Expr *expr = lfirst(lc2);
1693+
1694+
/* not needed for Consts */
1695+
if (!IsA(expr, Const))
1696+
{
1697+
int stateidx = PruneCxtStateIdx(partnatts,
1698+
step->step.step_id,
1699+
keyno);
16961700

1697-
context->exprstates[stateidx] =
1698-
ExecInitExpr(expr, context->planstate);
1701+
context->exprstates[stateidx] =
1702+
ExecInitExpr(expr, context->planstate);
1703+
}
1704+
lc2 = lnext(lc2);
16991705
}
1700-
keyno++;
17011706
}
17021707
}
17031708
}

0 commit comments

Comments
 (0)
0