fix_partition_missing_from_subplans_error.patch
application/octet-stream
Filename: fix_partition_missing_from_subplans_error.patch
Type: application/octet-stream
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/executor/execPartition.c | 8 | 2 |
| src/test/regress/expected/partition_prune.out | 18 | 0 |
| src/test/regress/sql/partition_prune.sql | 12 | 0 |
diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c
index d13be4145f..95814921fb 100644
--- a/src/backend/executor/execPartition.c
+++ b/src/backend/executor/execPartition.c
@@ -1886,8 +1886,14 @@ find_matching_subplans_recurse(PartitionPruningData *prunedata,
initial_prune, validsubplans);
else
{
- /* Shouldn't happen */
- elog(ERROR, "partition missing from subplans");
+ /*
+ * It's possible to get here for sub-partitioned tables when
+ * the planner found that none of the sub-partitions matched,
+ * therefore, pruned all its partitions. The same should
+ * happen here but we can't verify that as we have no pruning
+ * steps set up to call get_matching_partitions on the
+ * sub-partition, so let's just silently ignore it.
+ */
}
}
}
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index 693c348185..24313e8c78 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -3570,3 +3570,21 @@ execute q (1, 1);
reset plan_cache_mode;
drop table p, q;
+-- Ensure run-time pruning works correctly when we match a partitioned table
+-- on the first level but find no matching partitions on the second level.
+create table listp (a int, b int) partition by list (a);
+create table listp1 partition of listp for values in(1);
+create table listp2 partition of listp for values in(2) partition by list(b);
+create table listp2_10 partition of listp2 for values in (10);
+explain (analyze, costs off, summary off, timing off)
+select * from listp where a = (select 2) and b <> 10;
+ QUERY PLAN
+-------------------------------------------
+ Append (actual rows=0 loops=1)
+ InitPlan 1 (returns $0)
+ -> Result (actual rows=1 loops=1)
+ -> Seq Scan on listp1 (never executed)
+ Filter: ((b <> 10) AND (a = $0))
+(5 rows)
+
+drop table listp;
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 935c509b29..eca1a7c5ac 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -946,3 +946,15 @@ execute q (1, 1);
reset plan_cache_mode;
drop table p, q;
+
+-- Ensure run-time pruning works correctly when we match a partitioned table
+-- on the first level but find no matching partitions on the second level.
+create table listp (a int, b int) partition by list (a);
+create table listp1 partition of listp for values in(1);
+create table listp2 partition of listp for values in(2) partition by list(b);
+create table listp2_10 partition of listp2 for values in (10);
+
+explain (analyze, costs off, summary off, timing off)
+select * from listp where a = (select 2) and b <> 10;
+
+drop table listp;