diff options
| author | Amit Langote | 2025-02-25 00:21:17 +0000 |
|---|---|---|
| committer | Amit Langote | 2025-02-25 00:24:42 +0000 |
| commit | cbb9086c9ef64b020cb9036f50afc14644bbf734 (patch) | |
| tree | 215c47330d68db022a29bfab45279a14f3292ae3 /src/test | |
| parent | 48796a98d5aed68e349118d4e05ac26b76c765b0 (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/test')
| -rw-r--r-- | src/test/regress/expected/partition_prune.out | 48 | ||||
| -rw-r--r-- | src/test/regress/sql/partition_prune.sql | 12 |
2 files changed, 60 insertions, 0 deletions
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out index 1dbe6ff54fb..532597abe57 100644 --- a/src/test/regress/expected/partition_prune.out +++ b/src/test/regress/expected/partition_prune.out @@ -4590,5 +4590,53 @@ table part_abc_view; 2 | c | t (1 row) +-- A case with nested MergeAppend with its own PartitionPruneInfo. +create index on part_abc (a); +alter table part_abc add d int; +create table part_abc_3 partition of part_abc for values in (3, 4) partition by range (d); +create table part_abc_3_1 partition of part_abc_3 for values from (minvalue) to (1); +create table part_abc_3_2 partition of part_abc_3 for values from (1) to (100); +create table part_abc_3_3 partition of part_abc_3 for values from (100) to (maxvalue); +explain (costs off) +select min(a) over (partition by a order by a) from part_abc where a >= stable_one() + 1 and d <= stable_one() +union all +select min(a) over (partition by a order by a) from part_abc where a >= stable_one() + 1 and d >= stable_one(); + QUERY PLAN +---------------------------------------------------------------------------------------------- + Append + -> Subquery Scan on "*SELECT* 1_1" + -> WindowAgg + -> Append + Subplans Removed: 1 + -> Index Scan using part_abc_2_a_idx on part_abc_2 part_abc_1 + Index Cond: (a >= (stable_one() + 1)) + Filter: (d <= stable_one()) + -> Merge Append + Sort Key: part_abc_3.a + Subplans Removed: 1 + -> Index Scan using part_abc_3_1_a_idx on part_abc_3_1 part_abc_3 + Index Cond: (a >= (stable_one() + 1)) + Filter: (d <= stable_one()) + -> Index Scan using part_abc_3_2_a_idx on part_abc_3_2 part_abc_4 + Index Cond: (a >= (stable_one() + 1)) + Filter: (d <= stable_one()) + -> Subquery Scan on "*SELECT* 2" + -> WindowAgg + -> Append + Subplans Removed: 1 + -> Index Scan using part_abc_2_a_idx on part_abc_2 part_abc_6 + Index Cond: (a >= (stable_one() + 1)) + Filter: (d >= stable_one()) + -> Merge Append + Sort Key: a + Subplans Removed: 1 + -> Index Scan using part_abc_3_2_a_idx on part_abc_3_2 part_abc_8 + Index Cond: (a >= (stable_one() + 1)) + Filter: (d >= stable_one()) + -> Index Scan using part_abc_3_3_a_idx on part_abc_3_3 part_abc_9 + Index Cond: (a >= (stable_one() + 1)) + Filter: (d >= stable_one()) +(33 rows) + drop view part_abc_view; drop table part_abc; diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql index 6aad02156c6..5f36d589b6b 100644 --- a/src/test/regress/sql/partition_prune.sql +++ b/src/test/regress/sql/partition_prune.sql @@ -1397,5 +1397,17 @@ using (select stable_one() + 2 as pid) as q join part_abc_1 pt1 on (q.pid = pt1. when matched then delete returning pt.a; table part_abc_view; +-- A case with nested MergeAppend with its own PartitionPruneInfo. +create index on part_abc (a); +alter table part_abc add d int; +create table part_abc_3 partition of part_abc for values in (3, 4) partition by range (d); +create table part_abc_3_1 partition of part_abc_3 for values from (minvalue) to (1); +create table part_abc_3_2 partition of part_abc_3 for values from (1) to (100); +create table part_abc_3_3 partition of part_abc_3 for values from (100) to (maxvalue); +explain (costs off) +select min(a) over (partition by a order by a) from part_abc where a >= stable_one() + 1 and d <= stable_one() +union all +select min(a) over (partition by a order by a) from part_abc where a >= stable_one() + 1 and d >= stable_one(); + drop view part_abc_view; drop table part_abc; |
