]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix incorrect pruning of NULL partition for boolean IS NOT clauses
authorDavid Rowley <drowley@postgresql.org>
Mon, 19 Feb 2024 23:50:57 +0000 (12:50 +1300)
committerDavid Rowley <drowley@postgresql.org>
Mon, 19 Feb 2024 23:50:57 +0000 (12:50 +1300)
commitf9c8f7ccd6e34bc9222a09af3205600611bcda27
tree3e5d34a690c61aa90c29ec99213f0b886ce6aa95
parenteac4aff0b8a5d4cd003012ba4464bd0b39a9f875
Fix incorrect pruning of NULL partition for boolean IS NOT clauses

Partition pruning wrongly assumed that, for a table partitioned on a
boolean column, a clause in the form "boolcol IS NOT false" and "boolcol
IS NOT true" could be inverted to correspondingly become "boolcol IS true"
and "boolcol IS false".  These are not equivalent as the NOT version
matches the opposite boolean value *and* NULLs.  This incorrect assumption
meant that partition pruning pruned away partitions that could contain
NULL values.

Here we fix this by correctly not pruning partitions which could store
NULLs.

To be affected by this, the table must be partitioned by a NULLable boolean
column and queries would have to contain "boolcol IS NOT false" or "boolcol
IS NOT true".  This could result in queries filtering out NULL values
with a LIST partitioned table and "ERROR:  invalid strategy number 0"
for RANGE and HASH partitioned tables.

Reported-by: Alexander Lakhin
Bug: #18344
Discussion: https://postgr.es/m/18344-8d3f00bada6d09c6@postgresql.org
Backpatch-through: 12
src/backend/partitioning/partprune.c
src/test/regress/expected/partition_prune.out
src/test/regress/sql/partition_prune.sql