diff options
author | Richard Guo <rguo@postgresql.org> | 2024-12-09 20:36:23 +0900 |
---|---|---|
committer | Richard Guo <rguo@postgresql.org> | 2024-12-09 20:36:23 +0900 |
commit | 5668a857de4f3f12066b2bbc626b77be4fc95ee5 (patch) | |
tree | ccc5d2fb4f3d5b217f7e1e57338c87aa81b212ac /src/backend/executor/nodeHashjoin.c | |
parent | f0c569d7151532fbc9c016b01af49f04a9fb5278 (diff) | |
download | postgresql-5668a857de4f3f12066b2bbc626b77be4fc95ee5.tar.gz postgresql-5668a857de4f3f12066b2bbc626b77be4fc95ee5.zip |
Fix right-semi-joins in HashJoin rescans
When resetting a HashJoin node for rescans, if it is a single-batch
join and there are no parameter changes for the inner subnode, we can
just reuse the existing hash table without rebuilding it. However,
for join types that depend on the inner-tuple match flags in the hash
table, we need to reset these match flags to avoid incorrect results.
This applies to right, right-anti, right-semi, and full joins.
When I introduced "Right Semi Join" plan shapes in aa86129e1, I failed
to reset the match flags in the hash table for right-semi joins in
rescans. This oversight has been shown to produce incorrect results.
This patch fixes it.
Author: Richard Guo
Discussion: https://postgr.es/m/CAMbWs4-nQF9io2WL2SkD0eXvfPdyBc9Q=hRwfQHCGV2usa0jyA@mail.gmail.com
Diffstat (limited to 'src/backend/executor/nodeHashjoin.c')
-rw-r--r-- | src/backend/executor/nodeHashjoin.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/backend/executor/nodeHashjoin.c b/src/backend/executor/nodeHashjoin.c index 6c3009fba0f..ea0045bc0f3 100644 --- a/src/backend/executor/nodeHashjoin.c +++ b/src/backend/executor/nodeHashjoin.c @@ -1511,10 +1511,11 @@ ExecReScanHashJoin(HashJoinState *node) /* * Okay to reuse the hash table; needn't rescan inner, either. * - * However, if it's a right/right-anti/full join, we'd better - * reset the inner-tuple match flags contained in the table. + * However, if it's a right/right-anti/right-semi/full join, we'd + * better reset the inner-tuple match flags contained in the + * table. */ - if (HJ_FILL_INNER(node)) + if (HJ_FILL_INNER(node) || node->js.jointype == JOIN_RIGHT_SEMI) ExecHashTableResetMatchFlags(node->hj_HashTable); /* |