pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix incorrect non-strict join recheck in MERGE WHEN NOT MATCHED
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix incorrect non-strict join recheck in MERGE WHEN NOT MATCHED
@ 2024-10-03 11:54  Dean Rasheed <dean.a.rasheed@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Dean Rasheed @ 2024-10-03 11:54 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix incorrect non-strict join recheck in MERGE WHEN NOT MATCHED BY SOURCE.

If a MERGE command contains WHEN NOT MATCHED BY SOURCE actions, the
merge join condition is used by the executor to distinguish MATCHED
from NOT MATCHED BY SOURCE cases. However, this qual is executed using
the output from the join subplan node, which nulls the output from the
source relation in the not matched case, and so the result may be
incorrect if the join condition is "non-strict" -- for example,
something like "src.col IS NOT DISTINCT FROM tgt.col".

Fix this by enhancing the join recheck condition with an additional
"src IS NOT NULL" check, so that it does the right thing when
evaluated using the output from the join subplan.

Noted by Tom Lane while investigating bug #18634 from Alexander
Lakhin.

Back-patch to v17, where WHEN NOT MATCHED BY SOURCE support was added
to MERGE.

Discussion: https://postgr.es/m/18634-db5299c937877f2b%40postgresql.org

Branch
------
REL_17_STABLE

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

Modified Files
--------------
src/backend/optimizer/prep/prepjointree.c | 66 ++++++++++++++++++++++++++++---
src/test/regress/expected/merge.out       | 22 +++++++++++
src/test/regress/sql/merge.sql            | 18 +++++++++
3 files changed, 101 insertions(+), 5 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix incorrect non-strict join recheck in MERGE WHEN NOT MATCHED
@ 2024-10-03 11:54  Dean Rasheed <dean.a.rasheed@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Dean Rasheed @ 2024-10-03 11:54 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix incorrect non-strict join recheck in MERGE WHEN NOT MATCHED BY SOURCE.

If a MERGE command contains WHEN NOT MATCHED BY SOURCE actions, the
merge join condition is used by the executor to distinguish MATCHED
from NOT MATCHED BY SOURCE cases. However, this qual is executed using
the output from the join subplan node, which nulls the output from the
source relation in the not matched case, and so the result may be
incorrect if the join condition is "non-strict" -- for example,
something like "src.col IS NOT DISTINCT FROM tgt.col".

Fix this by enhancing the join recheck condition with an additional
"src IS NOT NULL" check, so that it does the right thing when
evaluated using the output from the join subplan.

Noted by Tom Lane while investigating bug #18634 from Alexander
Lakhin.

Back-patch to v17, where WHEN NOT MATCHED BY SOURCE support was added
to MERGE.

Discussion: https://postgr.es/m/18634-db5299c937877f2b%40postgresql.org

Branch
------
master

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

Modified Files
--------------
src/backend/optimizer/prep/prepjointree.c | 66 ++++++++++++++++++++++++++++---
src/test/regress/expected/merge.out       | 22 +++++++++++
src/test/regress/sql/merge.sql            | 18 +++++++++
3 files changed, 101 insertions(+), 5 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-10-03 11:54 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-10-03 11:54 pgsql: Fix incorrect non-strict join recheck in MERGE WHEN NOT MATCHED Dean Rasheed <dean.a.rasheed@gmail.com>
2024-10-03 11:54 pgsql: Fix incorrect non-strict join recheck in MERGE WHEN NOT MATCHED Dean Rasheed <dean.a.rasheed@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox