Skip to content

Commit 1eb9221

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 fa73b37 commit 1eb9221

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
@@ -1886,8 +1886,13 @@ find_matching_subplans_recurse(PartitionPruningData *prunedata,
18861886
initial_prune, validsubplans);
18871887
else
18881888
{
1889-
/* Shouldn't happen */
1890-
elog(ERROR, "partition missing from subplans");
1889+
/*
1890+
* We get here if the planner already pruned all the sub-
1891+
* partitions for this partition. Silently ignore this
1892+
* partition in this case. The end result is the same: we
1893+
* would have pruned all partitions just the same, but we
1894+
* don't have any pruning steps to execute to verify this.
1895+
*/
18911896
}
18921897
}
18931898
}

src/test/regress/expected/partition_prune.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3570,3 +3570,21 @@ execute q (1, 1);
35703570

35713571
reset plan_cache_mode;
35723572
drop table p, q;
3573+
-- Ensure run-time pruning works correctly when we match a partitioned table
3574+
-- on the first level but find no matching partitions on the second level.
3575+
create table listp (a int, b int) partition by list (a);
3576+
create table listp1 partition of listp for values in(1);
3577+
create table listp2 partition of listp for values in(2) partition by list(b);
3578+
create table listp2_10 partition of listp2 for values in (10);
3579+
explain (analyze, costs off, summary off, timing off)
3580+
select * from listp where a = (select 2) and b <> 10;
3581+
QUERY PLAN
3582+
-------------------------------------------
3583+
Append (actual rows=0 loops=1)
3584+
InitPlan 1 (returns $0)
3585+
-> Result (actual rows=1 loops=1)
3586+
-> Seq Scan on listp1 (never executed)
3587+
Filter: ((b <> 10) AND (a = $0))
3588+
(5 rows)
3589+
3590+
drop table listp;

src/test/regress/sql/partition_prune.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,3 +946,15 @@ execute q (1, 1);
946946

947947
reset plan_cache_mode;
948948
drop table p, q;
949+
950+
-- Ensure run-time pruning works correctly when we match a partitioned table
951+
-- on the first level but find no matching partitions on the second level.
952+
create table listp (a int, b int) partition by list (a);
953+
create table listp1 partition of listp for values in(1);
954+
create table listp2 partition of listp for values in(2) partition by list(b);
955+
create table listp2_10 partition of listp2 for values in (10);
956+
957+
explain (analyze, costs off, summary off, timing off)
958+
select * from listp where a = (select 2) and b <> 10;
959+
960+
drop table listp;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy