summaryrefslogtreecommitdiff
path: root/src/backend/partitioning
diff options
context:
space:
mode:
authorAmit Langote2025-02-25 00:21:17 +0000
committerAmit Langote2025-02-25 00:24:42 +0000
commitcbb9086c9ef64b020cb9036f50afc14644bbf734 (patch)
tree215c47330d68db022a29bfab45279a14f3292ae3 /src/backend/partitioning
parent48796a98d5aed68e349118d4e05ac26b76c765b0 (diff)
Fix bug in cbc127917 to handle nested Append correctly
A non-leaf partition with a subplan that is an Append node was omitted from PlannedStmt.unprunableRelids because it was mistakenly included in PlannerGlobal.prunableRelids due to the way PartitionedRelPruneInfo.leafpart_rti_map[] is constructed. This happened when a non-leaf partition used an unflattened Append or MergeAppend. As a result, ExecGetRangeTableRelation() reported an error when called from CreatePartitionPruneState() to process the partition's own PartitionPruneInfo, since it was treated as prunable when it should not have been. Reported-by: Alexander Lakhin <exclusion@gmail.com> (via sqlsmith) Diagnosed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Discussion: https://postgr.es/m/74839af6-aadc-4f60-ae77-ae65f94bf607@gmail.com
Diffstat (limited to 'src/backend/partitioning')
-rw-r--r--src/backend/partitioning/partprune.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c
index ff926732f36..48a35f763e9 100644
--- a/src/backend/partitioning/partprune.c
+++ b/src/backend/partitioning/partprune.c
@@ -687,7 +687,14 @@ make_partitionedrel_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel,
if (subplanidx >= 0)
{
present_parts = bms_add_member(present_parts, i);
- leafpart_rti_map[i] = (int) partrel->relid;
+
+ /*
+ * Non-leaf partitions may appear here when they use an
+ * unflattened Append or MergeAppend. These should not be
+ * included in prunableRelids.
+ */
+ if (partrel->nparts == -1)
+ leafpart_rti_map[i] = (int) partrel->relid;
/* Record finding this subplan */
subplansfound = bms_add_member(subplansfound, subplanidx);