pgsql: Allow ordered partition scans in more cases - Mailing list pgsql-committers

From David Rowley
Subject pgsql: Allow ordered partition scans in more cases
Date
Msg-id E1mAiG5-0006dy-5z@gemulon.postgresql.org
Whole thread Raw
List 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(-)


pgsql-committers by date:

Previous
From: David Rowley
Date:
Subject: pgsql: Track a Bitmapset of non-pruned partitions in RelOptInfo
Next
From: Thomas Munro
Date:
Subject: pgsql: Further simplify a bit of logic in StartupXLOG().