digoal
2021-08-03
PostgreSQL , sort , append scan , 分区有序返回
分区append scan支持更多order by 分区key 需求场景. 避免merge append需要mergesort的额外计算.
例如 list 分区, 如果分区可以有序(例如list某个分区内有多个value时, 只要能保证有序就可以用append scan). 也可以支持append scan for order by 场景了.
Allow ordered partition scans in more cases
author David Rowley <drowley@postgresql.org>
Tue, 3 Aug 2021 00:25:52 +0000 (12:25 +1200)
committer David Rowley <drowley@postgresql.org>
Tue, 3 Aug 2021 00:25:52 +0000 (12:25 +1200)
commit db632fbca392389807ffb9d9b2207157e8e9b3e8
tree 620f60d919288f919f8af66abcfb2598591d2678 tree
parent 475dbd0b718de8ac44da144f934651b959e3b705 commit | diff
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
您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.