public inbox for [email protected]
help / color / mirror / Atom feedFrom: Richard Guo <[email protected]>
To: PostgreSQL-development <[email protected]>
Subject: Short-circuit sort_inner_and_outer if there are no mergejoin clauses
Date: Wed, 24 Apr 2024 17:13:12 +0800
Message-ID: <CAMbWs48RKiZGFEd5A0JtztRY5ZdvVvNiHh0AKeuoz21F+0dVjQ@mail.gmail.com> (raw)
In sort_inner_and_outer, we create mergejoin join paths by explicitly
sorting both relations on each possible ordering of the available
mergejoin clauses. However, if there are no available mergejoin
clauses, we can skip this process entirely. It seems that this is a
relatively common scenario. Checking the regression tests I noticed
that there are a lot of cases where we would arrive here with an empty
mergeclause_list.
So I'm wondering if it's worth considering a shortcut in
sort_inner_and_outer by checking if mergeclause_list is empty. This can
help skip all the statements preceding select_outer_pathkeys_for_merge.
In particular this may help avoid building UniquePath paths in the case
of JOIN_UNIQUE_OUTER or JOIN_UNIQUE_INNER.
I asked this because in the "Right Semi Join" patch [1] I wanted to
exclude mergejoin from being considered for JOIN_RIGHT_SEMI. So I set
mergeclause_list to NIL, but noticed that it still runs the statements
in sort_inner_and_outer until no available outer pathkeys are found in
select_outer_pathkeys_for_merge.
Attached is a trivial patch for this. Thoughts?
[1]
https://www.postgresql.org/message-id/flat/CAMbWs4_X1mN%3Dic%2BSxcyymUqFx9bB8pqSLTGJ-F%3DMHy4PW3eRXw...
Thanks
Richard
Attachments:
[application/octet-stream] v1-0001-Short-circuit-sort_inner_and_outer-if-there-are-no-mergejoin-clauses.patch (1.5K, ../CAMbWs48RKiZGFEd5A0JtztRY5ZdvVvNiHh0AKeuoz21F+0dVjQ@mail.gmail.com/3-v1-0001-Short-circuit-sort_inner_and_outer-if-there-are-no-mergejoin-clauses.patch)
download | inline diff:
From c0b017f6494a60c7f5102d5af9428188b7a61ffc Mon Sep 17 00:00:00 2001
From: Richard Guo <[email protected]>
Date: Wed, 24 Apr 2024 09:04:48 +0000
Subject: [PATCH v1] Short-circuit sort_inner_and_outer if there are no
mergejoin clauses
In sort_inner_and_outer, we create mergejoin join paths by explicitly
sorting both relations on each possible ordering of the available
mergejoin clauses. However, if there are no available mergejoin
clauses, we can skip this process entirely.
This patch introduces a check for mergeclause_list at the beginning of
sort_inner_and_outer and exits the function if it is found to be empty.
This might help skip all the statements that come before the call to
select_outer_pathkeys_for_merge, including the build of UniquePath paths
in the case of JOIN_UNIQUE_OUTER or JOIN_UNIQUE_INNER.
---
src/backend/optimizer/path/joinpath.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/backend/optimizer/path/joinpath.c b/src/backend/optimizer/path/joinpath.c
index 5be8da9e09..dbbc18e56c 100644
--- a/src/backend/optimizer/path/joinpath.c
+++ b/src/backend/optimizer/path/joinpath.c
@@ -1278,6 +1278,10 @@ sort_inner_and_outer(PlannerInfo *root,
List *all_pathkeys;
ListCell *l;
+ /* Nothing to do if there are no available mergejoin clauses */
+ if (extra->mergeclause_list == NIL)
+ return;
+
/*
* We only consider the cheapest-total-cost input paths, since we are
* assuming here that a sort is required. We will consider
--
2.34.1
view thread (2+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: Short-circuit sort_inner_and_outer if there are no mergejoin clauses
In-Reply-To: <CAMbWs48RKiZGFEd5A0JtztRY5ZdvVvNiHh0AKeuoz21F+0dVjQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox