pgsql: Allow ordered partition scans in more cases

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Allow ordered partition scans in more cases
Date: 2021-08-03 00:26:13
Message-ID: E1mAiG5-0006dy-5z@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Allow ordered partition scans in more cases

959d00e9d added the ability to make use of an Append node instead of a
MergeAppend when we wanted to perform a scan of a partitioned table and
the required sort order was the same as the partitioned keys and the
partitioned table was defined in such a way that earlier partitions were
guaranteed to only contain lower-order values than later partitions.
However, previously we didn't allow these ordered partition scans for
LIST partitioned table when there were any partitions that allowed
multiple Datums. This was a very cheap check to make and we could likely
have done a little better by checking if there were interleaved
partitions, but at the time we didn't have visibility about which
partitions were pruned, so we still may have disallowed cases where all
interleaved partitions were pruned.

Since 475dbd0b7, we now have knowledge of pruned partitions, we can do a
much better job inside partitions_are_ordered().

Here we pass which partitions survived partition pruning into
partitions_are_ordered() and, for LIST partitioning, have it check to see
if any live partitions exist that are also in the new "interleaved_parts"
field defined in PartitionBoundInfo.

For RANGE partitioning we can relax the code which caused the partitions
to be unordered if a DEFAULT partition existed. Since we now know which
partitions were pruned, partitions_are_ordered() now returns true when the
DEFAULT partition was pruned.

Reviewed-by: Amit Langote, Zhihong Yu
Discussion: https://postgr.es/m/CAApHDvrdoN_sXU52i=QDXe2k3WAo=EVry29r2+Tq2WYcn2xhEA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/db632fbca392389807ffb9d9b2207157e8e9b3e8

Modified Files
--------------
src/backend/optimizer/path/allpaths.c | 2 +-
src/backend/optimizer/path/pathkeys.c | 2 +-
src/backend/partitioning/partbounds.c | 105 +++++++++++++++++++++++++--------
src/include/partitioning/partbounds.h | 18 +++++-
src/test/regress/expected/inherit.out | 108 ++++++++++++++++++++++++++++++++++
src/test/regress/sql/inherit.sql | 27 +++++++++
6 files changed, 235 insertions(+), 27 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Thomas Munro 2021-08-03 02:18:58 pgsql: Further simplify a bit of logic in StartupXLOG().
Previous Message David Rowley 2021-08-02 23:47:59 pgsql: Track a Bitmapset of non-pruned partitions in RelOptInfo