From c0b017f6494a60c7f5102d5af9428188b7a61ffc Mon Sep 17 00:00:00 2001 From: Richard Guo 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