mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Fix partition pruning with IS [NOT] NULL clauses
The original code was unable to prune partitions that could not possibly contain NULL values, when the query specified less than all columns in a multicolumn partition key. Reorder the if-tests so that it is, and add more commentary and regression tests. Reported-by: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com> Co-authored-by: Dilip Kumar <dilipbalaut@gmail.com> Co-authored-by: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp> Co-authored-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Reviewed-by: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com> Reviewed-by: amul sul <sulamul@gmail.com> Discussion: https://postgr.es/m/CAFjFpRc7qjLUfXLVBBC_HAnx644sjTYM=qVoT3TJ840HPbsTXw@mail.gmail.com
This commit is contained in:
@ -993,6 +993,47 @@ explain (costs off) select * from mc2p where a = 1 and b > 1;
|
||||
Filter: ((b > 1) AND (a = 1))
|
||||
(3 rows)
|
||||
|
||||
-- all partitions but the default one should be pruned
|
||||
explain (costs off) select * from mc2p where a = 1 and b is null;
|
||||
QUERY PLAN
|
||||
-------------------------------------------
|
||||
Append
|
||||
-> Seq Scan on mc2p_default
|
||||
Filter: ((b IS NULL) AND (a = 1))
|
||||
(3 rows)
|
||||
|
||||
explain (costs off) select * from mc2p where a is null and b is null;
|
||||
QUERY PLAN
|
||||
-----------------------------------------------
|
||||
Append
|
||||
-> Seq Scan on mc2p_default
|
||||
Filter: ((a IS NULL) AND (b IS NULL))
|
||||
(3 rows)
|
||||
|
||||
explain (costs off) select * from mc2p where a is null and b = 1;
|
||||
QUERY PLAN
|
||||
-------------------------------------------
|
||||
Append
|
||||
-> Seq Scan on mc2p_default
|
||||
Filter: ((a IS NULL) AND (b = 1))
|
||||
(3 rows)
|
||||
|
||||
explain (costs off) select * from mc2p where a is null;
|
||||
QUERY PLAN
|
||||
--------------------------------
|
||||
Append
|
||||
-> Seq Scan on mc2p_default
|
||||
Filter: (a IS NULL)
|
||||
(3 rows)
|
||||
|
||||
explain (costs off) select * from mc2p where b is null;
|
||||
QUERY PLAN
|
||||
--------------------------------
|
||||
Append
|
||||
-> Seq Scan on mc2p_default
|
||||
Filter: (b IS NULL)
|
||||
(3 rows)
|
||||
|
||||
-- boolean partitioning
|
||||
create table boolpart (a bool) partition by list (a);
|
||||
create table boolpart_default partition of boolpart default;
|
||||
|
@ -137,6 +137,13 @@ explain (costs off) select * from mc2p where a = 2 and b < 1;
|
||||
explain (costs off) select * from mc2p where a > 1;
|
||||
explain (costs off) select * from mc2p where a = 1 and b > 1;
|
||||
|
||||
-- all partitions but the default one should be pruned
|
||||
explain (costs off) select * from mc2p where a = 1 and b is null;
|
||||
explain (costs off) select * from mc2p where a is null and b is null;
|
||||
explain (costs off) select * from mc2p where a is null and b = 1;
|
||||
explain (costs off) select * from mc2p where a is null;
|
||||
explain (costs off) select * from mc2p where b is null;
|
||||
|
||||
-- boolean partitioning
|
||||
create table boolpart (a bool) partition by list (a);
|
||||
create table boolpart_default partition of boolpart default;
|
||||
|
Reference in New Issue
Block a user