pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix cross-partition source values in MERGE after a concurrent up 4+ messages / 1 participants [nested] [flat]
* pgsql: Fix cross-partition source values in MERGE after a concurrent up @ 2026-11-23 12:21 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 4+ messages in thread From: Dean Rasheed @ 2026-11-23 12:21 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix cross-partition source values in MERGE after a concurrent update. Follow-up to commit b291954ea5a. When a concurrent update causes MERGE to switch from a WHEN MATCHED action to a WHEN NOT MATCHED BY SOURCE action, any source values returned should be NULL, not the source values from the originally matched tuple. Commit b291954ea5a attempted to ensure this by building a new all-NULL slot for use in the RETURNING projection, when ExecMergeMatched() transitions from WHEN MATCHED to WHEN NOT MATCHED BY SOURCE after a concurrent update. However, this overlooked the code path taken for a cross-partition update, which executes ExecProcessReturning() from ExecInsert() rather than directly from ExecMergeMatched(). Fix by temporarily replacing the ModifyTableContext planSlot with the new all-NULL slot while the WHEN NOT MATCHED BY SOURCE action is executed, so that the correct NULL source values are seen by all code executed as part of the action. Backpatch to v17, where WHEN NOT MATCHED BY SOURCE support was added to MERGE. Reported-by: Tender Wang <tndrwang@gmail.com> Author: Tender Wang <tndrwang@gmail.com> Author: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://postgr.es/m/CAHewXNkZb5rBnen7ALsXX3d5JgdpzUjsNY9pqbxub3N-%2BNb%3DyQ%40mail.gmail.com Backpatch-through: 17 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/fd59a73274251f43278e93ac1a71c085241704e9 Modified Files -------------- src/backend/executor/nodeModifyTable.c | 29 +++--- src/test/isolation/expected/merge-not-matched.out | 112 ++++++++++++++++++++++ src/test/isolation/specs/merge-not-matched.spec | 38 +++++++- 3 files changed, 163 insertions(+), 16 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix cross-partition source values in MERGE after a concurrent up @ 2026-11-23 12:21 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 4+ messages in thread From: Dean Rasheed @ 2026-11-23 12:21 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix cross-partition source values in MERGE after a concurrent update. Follow-up to commit b291954ea5a. When a concurrent update causes MERGE to switch from a WHEN MATCHED action to a WHEN NOT MATCHED BY SOURCE action, any source values returned should be NULL, not the source values from the originally matched tuple. Commit b291954ea5a attempted to ensure this by building a new all-NULL slot for use in the RETURNING projection, when ExecMergeMatched() transitions from WHEN MATCHED to WHEN NOT MATCHED BY SOURCE after a concurrent update. However, this overlooked the code path taken for a cross-partition update, which executes ExecProcessReturning() from ExecInsert() rather than directly from ExecMergeMatched(). Fix by temporarily replacing the ModifyTableContext planSlot with the new all-NULL slot while the WHEN NOT MATCHED BY SOURCE action is executed, so that the correct NULL source values are seen by all code executed as part of the action. Backpatch to v17, where WHEN NOT MATCHED BY SOURCE support was added to MERGE. Reported-by: Tender Wang <tndrwang@gmail.com> Author: Tender Wang <tndrwang@gmail.com> Author: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://postgr.es/m/CAHewXNkZb5rBnen7ALsXX3d5JgdpzUjsNY9pqbxub3N-%2BNb%3DyQ%40mail.gmail.com Backpatch-through: 17 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/6f1827b00b752570cacfd6000be31dd8f7454b16 Modified Files -------------- src/backend/executor/nodeModifyTable.c | 29 +++--- src/test/isolation/expected/merge-not-matched.out | 112 ++++++++++++++++++++++ src/test/isolation/specs/merge-not-matched.spec | 38 +++++++- 3 files changed, 163 insertions(+), 16 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix cross-partition source values in MERGE after a concurrent up @ 2026-11-23 12:21 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 4+ messages in thread From: Dean Rasheed @ 2026-11-23 12:21 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix cross-partition source values in MERGE after a concurrent update. Follow-up to commit b291954ea5a. When a concurrent update causes MERGE to switch from a WHEN MATCHED action to a WHEN NOT MATCHED BY SOURCE action, any source values returned should be NULL, not the source values from the originally matched tuple. Commit b291954ea5a attempted to ensure this by building a new all-NULL slot for use in the RETURNING projection, when ExecMergeMatched() transitions from WHEN MATCHED to WHEN NOT MATCHED BY SOURCE after a concurrent update. However, this overlooked the code path taken for a cross-partition update, which executes ExecProcessReturning() from ExecInsert() rather than directly from ExecMergeMatched(). Fix by temporarily replacing the ModifyTableContext planSlot with the new all-NULL slot while the WHEN NOT MATCHED BY SOURCE action is executed, so that the correct NULL source values are seen by all code executed as part of the action. Backpatch to v17, where WHEN NOT MATCHED BY SOURCE support was added to MERGE. Reported-by: Tender Wang <tndrwang@gmail.com> Author: Tender Wang <tndrwang@gmail.com> Author: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://postgr.es/m/CAHewXNkZb5rBnen7ALsXX3d5JgdpzUjsNY9pqbxub3N-%2BNb%3DyQ%40mail.gmail.com Backpatch-through: 17 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/a95dcec5dc0b54b20b606fce021c6e6cffd0adbc Modified Files -------------- src/backend/executor/nodeModifyTable.c | 29 +++--- src/test/isolation/expected/merge-not-matched.out | 112 ++++++++++++++++++++++ src/test/isolation/specs/merge-not-matched.spec | 38 +++++++- 3 files changed, 163 insertions(+), 16 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix cross-partition source values in MERGE after a concurrent up @ 2026-11-23 12:21 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 4+ messages in thread From: Dean Rasheed @ 2026-11-23 12:21 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix cross-partition source values in MERGE after a concurrent update. Follow-up to commit b291954ea5a. When a concurrent update causes MERGE to switch from a WHEN MATCHED action to a WHEN NOT MATCHED BY SOURCE action, any source values returned should be NULL, not the source values from the originally matched tuple. Commit b291954ea5a attempted to ensure this by building a new all-NULL slot for use in the RETURNING projection, when ExecMergeMatched() transitions from WHEN MATCHED to WHEN NOT MATCHED BY SOURCE after a concurrent update. However, this overlooked the code path taken for a cross-partition update, which executes ExecProcessReturning() from ExecInsert() rather than directly from ExecMergeMatched(). Fix by temporarily replacing the ModifyTableContext planSlot with the new all-NULL slot while the WHEN NOT MATCHED BY SOURCE action is executed, so that the correct NULL source values are seen by all code executed as part of the action. Backpatch to v17, where WHEN NOT MATCHED BY SOURCE support was added to MERGE. Reported-by: Tender Wang <tndrwang@gmail.com> Author: Tender Wang <tndrwang@gmail.com> Author: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://postgr.es/m/CAHewXNkZb5rBnen7ALsXX3d5JgdpzUjsNY9pqbxub3N-%2BNb%3DyQ%40mail.gmail.com Backpatch-through: 17 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/19db7e5b36e33c80a032e0e811176ad3b115b0ca Modified Files -------------- src/backend/executor/nodeModifyTable.c | 29 +++--- src/test/isolation/expected/merge-not-matched.out | 112 ++++++++++++++++++++++ src/test/isolation/specs/merge-not-matched.spec | 38 +++++++- 3 files changed, 163 insertions(+), 16 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2026-11-23 12:21 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-11-23 12:21 pgsql: Fix cross-partition source values in MERGE after a concurrent up Dean Rasheed <dean.a.rasheed@gmail.com> 2026-11-23 12:21 pgsql: Fix cross-partition source values in MERGE after a concurrent up Dean Rasheed <dean.a.rasheed@gmail.com> 2026-11-23 12:21 pgsql: Fix cross-partition source values in MERGE after a concurrent up Dean Rasheed <dean.a.rasheed@gmail.com> 2026-11-23 12:21 pgsql: Fix cross-partition source values in MERGE after a concurrent up 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