pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix wrong varnullingrels error for MERGE WHEN NOT MATCHED BY SOU
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix wrong varnullingrels error for MERGE WHEN NOT MATCHED BY SOU
@ 2024-10-03 12:49  Dean Rasheed <dean.a.rasheed@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

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

Fix wrong varnullingrels error for MERGE WHEN NOT MATCHED BY SOURCE.

If a MERGE command contains WHEN NOT MATCHED BY SOURCE actions, the
source relation appears on the outer side of the join. Thus, any Vars
referring to the source in the merge join condition, actions, and
RETURNING list should be marked as nullable by the join, since they
are used in the ModifyTable node above the join. Note that this only
applies to the copy of join condition used in the executor to
distinguish MATCHED from NOT MATCHED BY SOURCE cases. Vars in the
original join condition, inside the join node itself, should not be
marked.

Failure to correctly mark these Vars led to a "wrong varnullingrels"
error in the final stage of query planning, in some circumstances. We
happened to get away without this in all previous tests, since they
all involved a ModifyTable node directly on top of the join node, so
that the top plan targetlist coincided with the output of the join,
and the varnullingrels check was more lax. However, if another plan
node, such as a one-time filter Result node, gets inserted between the
ModifyTable node and the join node, then a stricter check is applied,
which fails.

Per bug #18634 from Alexander Lakhin. Thanks to Tom Lane and Richard
Guo for review and analysis.

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/259a0a99fe3d45dcf624788c1724d9989f3382dc

Modified Files
--------------
src/backend/optimizer/prep/prepjointree.c | 39 +++++++++++++++++++++++++++++++
src/test/regress/expected/merge.out       | 29 +++++++++++++++++++++++
src/test/regress/sql/merge.sql            | 21 +++++++++++++++++
3 files changed, 89 insertions(+)



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

* pgsql: Fix wrong varnullingrels error for MERGE WHEN NOT MATCHED BY SOU
@ 2024-10-03 12:49  Dean Rasheed <dean.a.rasheed@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

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

Fix wrong varnullingrels error for MERGE WHEN NOT MATCHED BY SOURCE.

If a MERGE command contains WHEN NOT MATCHED BY SOURCE actions, the
source relation appears on the outer side of the join. Thus, any Vars
referring to the source in the merge join condition, actions, and
RETURNING list should be marked as nullable by the join, since they
are used in the ModifyTable node above the join. Note that this only
applies to the copy of join condition used in the executor to
distinguish MATCHED from NOT MATCHED BY SOURCE cases. Vars in the
original join condition, inside the join node itself, should not be
marked.

Failure to correctly mark these Vars led to a "wrong varnullingrels"
error in the final stage of query planning, in some circumstances. We
happened to get away without this in all previous tests, since they
all involved a ModifyTable node directly on top of the join node, so
that the top plan targetlist coincided with the output of the join,
and the varnullingrels check was more lax. However, if another plan
node, such as a one-time filter Result node, gets inserted between the
ModifyTable node and the join node, then a stricter check is applied,
which fails.

Per bug #18634 from Alexander Lakhin. Thanks to Tom Lane and Richard
Guo for review and analysis.

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/34ae54af92e006e601f808e58765cc979ca9135f

Modified Files
--------------
src/backend/optimizer/prep/prepjointree.c | 39 +++++++++++++++++++++++++++++++
src/test/regress/expected/merge.out       | 29 +++++++++++++++++++++++
src/test/regress/sql/merge.sql            | 21 +++++++++++++++++
3 files changed, 89 insertions(+)



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


end of thread, other threads:[~2024-10-03 12:49 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 12:49 pgsql: Fix wrong varnullingrels error for MERGE WHEN NOT MATCHED BY SOU Dean Rasheed <dean.a.rasheed@gmail.com>
2024-10-03 12:49 pgsql: Fix wrong varnullingrels error for MERGE WHEN NOT MATCHED BY SOU 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