agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix pruning of DEFAULT partition in RANGE partitioned tables
Date: Fri, 18 Sep 2026 05:16:15 +0000
Message-ID: <E1x7QxL-00000000DL6-2rmO@gemulon.postgresql.org> (raw)
Fix pruning of DEFAULT partition in RANGE partitioned tables
Some code added in 489247b0e tried to prune the DEFAULT partition when
the next partition had a MINVALUE clause and likewise when the final
partition to scan had a MAXVALUE clause for the final partition key in
the pruning step. This code was incorrect as it could prune the default
partition incorrectly in cases such as:
p: PARTITION BY RANGE (a, b)
p1: FOR VALUES FROM (13, 0) TO (19, MAXVALUE)
pd: DEFAULT
SELECT * FROM t WHERE a = 32 AND b >= -7;
Here the pruning step for a = 32 and b >= -7 would see that only the
default partition needs to be scan, but it would then see that the
partition prior to the default had a MAXVALUE bound then prune away the
default thinking that it needn't be scanned. This could result in
incorrect results.
Fix this by moving the code that looks for the MAXVALUE bound into the
code handling BTEqualStrategyNumber so that when we're pruning with a
prefix of the partition keys, we check if the bound for the offset we've
calculated lands on a partition where the next partition key is bounded
with MAXVALUE. If so we don't include the default partition.
This leaves only the case of the first partition key. We handle that by
modifying the existing code that was checking the last key covered by
the given values.
Author: Ewan Young <kdbase.hack@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAON2xHO=sqdqp=z8zWkybnWp0AuvefnAi2ez2vOYWrhXB6hHWQ@mail.gmail.com
Backpatch-through: 14
Branch
------
REL_17_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/d21d4f1ca0c44ecf9f75c0519e1c034d0fb3b630
Modified Files
--------------
src/backend/partitioning/partprune.c | 62 ++++++++++--------
src/test/regress/expected/partition_prune.out | 94 +++++++++++++++++++++++++++
src/test/regress/sql/partition_prune.sql | 47 ++++++++++++++
3 files changed, 177 insertions(+), 26 deletions(-)
view thread (7+ messages) latest in thread
Message-ID: <E1x7QxL-00000000DL6-2rmO@gemulon.postgresql.org>
Permalink: ../E1x7QxL-00000000DL6-2rmO@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1x7QxL-00000000DL6-2rmO@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: drowley@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Fix pruning of DEFAULT partition in RANGE partitioned tables
In-Reply-To: <E1x7QxL-00000000DL6-2rmO@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox