Short-circuit sort_inner_and_outer if there are no mergejoin clauses - Mailing list pgsql-hackers

From Richard Guo
Subject Short-circuit sort_inner_and_outer if there are no mergejoin clauses
Date
Msg-id CAMbWs48RKiZGFEd5A0JtztRY5ZdvVvNiHh0AKeuoz21F+0dVjQ@mail.gmail.com
Whole thread Raw
Responses Re: Short-circuit sort_inner_and_outer if there are no mergejoin clauses
List pgsql-hackers
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?

Attachment

pgsql-hackers by date:

Previous
From: "Anton A. Melnikov"
Date:
Subject: Re: Use XLOG_CONTROL_FILE macro everywhere?
Next
From: Anthonin Bonnefoy
Date:
Subject: Re: Fix parallel vacuum buffer usage reporting