Support "Right Semi Join" plan shapes
commitaa86129e19d704afb93cb84ab9638f33d266ee9d
authorRichard Guo <rguo@postgresql.org>
Fri, 5 Jul 2024 00:26:48 +0000 (5 09:26 +0900)
committerRichard Guo <rguo@postgresql.org>
Fri, 5 Jul 2024 00:26:48 +0000 (5 09:26 +0900)
tree0c1643a4ca9aaa321c08f4d896499aed3c961c2c
parent5a519abeddfe34659a8c0478f04a0acfd0d80ec6
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
14 files changed:
contrib/postgres_fdw/expected/postgres_fdw.out
src/backend/commands/explain.c
src/backend/executor/nodeHashjoin.c
src/backend/optimizer/path/joinpath.c
src/backend/optimizer/path/joinrels.c
src/backend/optimizer/path/pathkeys.c
src/backend/optimizer/prep/prepjointree.c
src/include/nodes/nodes.h
src/include/nodes/pathnodes.h
src/test/regress/expected/join.out
src/test/regress/expected/partition_join.out
src/test/regress/expected/select_parallel.out
src/test/regress/expected/updatable_views.out
src/test/regress/sql/join.sql