Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6589a43

Browse files
committed
Fix executor prune failure when plan already pruned
In a multi-layer partitioning setup, if at plan time all the sub-partitions are pruned but the intermediate one remains, the executor later throws a spurious error that there's nothing to prune. That is correct, but there's no reason to throw an error. Therefore, don't. Reported-by: Andreas Seltenreich <seltenreich@gmx.de> Author: David Rowley <david.rowley@2ndquadrant.com> Discussion: https://postgr.es/m/87in4h98i0.fsf@ansel.ydns.eu
1 parent 43ba5ac commit 6589a43

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/backend/executor/execPartition.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,8 +1887,13 @@ find_matching_subplans_recurse(PartitionPruningData *prunedata,
18871887
initial_prune, validsubplans);
18881888
else
18891889
{
1890-
/* Shouldn't happen */
1891-
elog(ERROR, "partition missing from subplans");
1890+
/*
1891+
* We get here if the planner already pruned all the sub-
1892+
* partitions for this partition. Silently ignore this
1893+
* partition in this case. The end result is the same: we
1894+
* would have pruned all partitions just the same, but we
1895+
* don't have any pruning steps to execute to verify this.
1896+
*/
18921897
}
18931898
}
18941899
}

src/test/regress/expected/partition_prune.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,3 +3400,21 @@ where s.a = 1 and s.b = 1 and s.c = (select 1);
34003400
(1 row)
34013401

34023402
drop table p, q;
3403+
-- Ensure run-time pruning works correctly when we match a partitioned table
3404+
-- on the first level but find no matching partitions on the second level.
3405+
create table listp (a int, b int) partition by list (a);
3406+
create table listp1 partition of listp for values in(1);
3407+
create table listp2 partition of listp for values in(2) partition by list(b);
3408+
create table listp2_10 partition of listp2 for values in (10);
3409+
explain (analyze, costs off, summary off, timing off)
3410+
select * from listp where a = (select 2) and b <> 10;
3411+
QUERY PLAN
3412+
-------------------------------------------
3413+
Append (actual rows=0 loops=1)
3414+
InitPlan 1 (returns $0)
3415+
-> Result (actual rows=1 loops=1)
3416+
-> Seq Scan on listp1 (never executed)
3417+
Filter: ((b <> 10) AND (a = $0))
3418+
(5 rows)
3419+
3420+
drop table listp;

src/test/regress/sql/partition_prune.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,3 +888,15 @@ from (
888888
where s.a = 1 and s.b = 1 and s.c = (select 1);
889889

890890
drop table p, q;
891+
892+
-- Ensure run-time pruning works correctly when we match a partitioned table
893+
-- on the first level but find no matching partitions on the second level.
894+
create table listp (a int, b int) partition by list (a);
895+
create table listp1 partition of listp for values in(1);
896+
create table listp2 partition of listp for values in(2) partition by list(b);
897+
create table listp2_10 partition of listp2 for values in (10);
898+
899+
explain (analyze, costs off, summary off, timing off)
900+
select * from listp where a = (select 2) and b <> 10;
901+
902+
drop table listp;

0 commit comments

Comments
 (0)