1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-09 06:21:09 +03:00

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
This commit is contained in:
Richard Guo
2025-05-08 18:21:32 +09:00
parent 773db22269
commit c06e909c26
8 changed files with 104 additions and 66 deletions

View File

@@ -821,8 +821,9 @@ GetExistingLocalJoinPath(RelOptInfo *joinrel)
* for the mergejoin, we can skip doing an explicit sort.
*/
if (merge_path->outersortkeys &&
pathkeys_contained_in(merge_path->outersortkeys,
joinpath->outerjoinpath->pathkeys))
pathkeys_count_contained_in(merge_path->outersortkeys,
joinpath->outerjoinpath->pathkeys,
&merge_path->outer_presorted_keys))
merge_path->outersortkeys = NIL;
}
}