pgsql: Support "Right Semi Join" plan shapes

From: Richard Guo <rguo(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Support "Right Semi Join" plan shapes
Date: 2024-07-05 00:29:54
Message-ID: E1sPWpl-000LqW-IW@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Support "Right Semi Join" plan shapes

Hash joins can support semijoin with the LHS input on the right, using
the existing logic for inner join, combined with the assurance that only
the first match for each inner tuple is considered, which can be
achieved by leveraging the HEAP_TUPLE_HAS_MATCH flag. This can be very
useful in some cases since we may now have the option to hash the
smaller table instead of the larger.

Merge join could likely support "Right Semi Join" too. However, the
benefit of swapping inputs tends to be small here, so we do not address
that in this patch.

Note that this patch also modifies a test query in join.sql to ensure it
continues testing as intended. With this patch the original query would
result in a right-semi-join rather than semi-join, compromising its
original purpose of testing the fix for neqjoinsel's behavior for
semi-joins.

Author: Richard Guo
Reviewed-by: wenhui qiu, Alena Rybakina, Japin Li
Discussion: https://postgr.es/m/CAMbWs4_X1mN=ic+SxcyymUqFx9bB8pqSLTGJ-F=MHy4PW3eRXw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/aa86129e19d704afb93cb84ab9638f33d266ee9d

Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out | 15 +-
src/backend/commands/explain.c | 3 +
src/backend/executor/nodeHashjoin.c | 15 +-
src/backend/optimizer/path/joinpath.c | 42 +++--
src/backend/optimizer/path/joinrels.c | 3 +
src/backend/optimizer/path/pathkeys.c | 3 +
src/backend/optimizer/prep/prepjointree.c | 6 +-
src/include/nodes/nodes.h | 9 +-
src/include/nodes/pathnodes.h | 6 +-
src/test/regress/expected/join.out | 27 ++--
src/test/regress/expected/partition_join.out | 216 +++++++++++++------------
src/test/regress/expected/select_parallel.out | 32 ++--
src/test/regress/expected/updatable_views.out | 6 +-
src/test/regress/sql/join.sql | 8 +-
14 files changed, 220 insertions(+), 171 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2024-07-05 02:05:29 pgsql: Add memory/disk usage for Material nodes in EXPLAIN
Previous Message Michael Paquier 2024-07-04 23:18:33 Re: pgsql: Add pg_get_acl() to get the ACL for a database object