Track the number of presorted outer pathkeys in MergePath
authorRichard Guo <rguo@postgresql.org>
Thu, 8 May 2025 09:21:32 +0000 (18:21 +0900)
committerRichard Guo <rguo@postgresql.org>
Thu, 8 May 2025 09:21:32 +0000 (18:21 +0900)
commitc06e909c26f070dee78f73c35565d6f4a4ffdcda
tree9f69470d8ba03027f37796542b8c0e7bafb2f44e
parent773db22269d474fab46d25e9e15b1e55252cf92c
Track the number of presorted outer pathkeys in MergePath

When creating an explicit Sort node for the outer path of a mergejoin,
we need to determine the number of presorted keys of the outer path to
decide whether explicit incremental sort can be applied.  Currently,
this is done by repeatedly calling pathkeys_count_contained_in.

This patch caches the number of presorted outer pathkeys in MergePath,
allowing us to save several calls to pathkeys_count_contained_in.  It
can be considered a complement to the changes in commit 828e94c9d.

Reported-by: David Rowley <dgrowleyml@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Discussion: https://postgr.es/m/CAApHDvqvBireB_w6x8BN5txdvBEHxVgZBt=rUnpf5ww5P_E_ww@mail.gmail.com
src/backend/foreign/foreign.c
src/backend/optimizer/path/costsize.c
src/backend/optimizer/path/joinpath.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/util/pathnode.c
src/include/nodes/pathnodes.h
src/include/optimizer/cost.h
src/include/optimizer/pathnode.h