agora inbox for pgsql-committers@postgresql.orghelp / color / mirror / Atom feed
pgsql: Avoid RETURNING side effects for FOR PORTION OF leftovers. 2+ messages / 1 participants [nested] [flat]
* pgsql: Avoid RETURNING side effects for FOR PORTION OF leftovers. @ 2026-07-28 08:48 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 2+ messages in thread From: Dean Rasheed @ 2026-07-28 08:48 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid RETURNING side effects for FOR PORTION OF leftovers. UPDATE/DELETE ... FOR PORTION OF inserts leftover rows for the untouched parts of the original row. These hidden inserts should not affect the command tag or ROW_COUNT, so they call ExecInsert() with canSetTag set to false. However, ExecInsert() still processed the RETURNING list whenever the target ResultRelInfo had ri_projectReturning set. That caused RETURNING expressions to be evaluated for leftover rows even though their results were discarded. As a result, expressions with side effects and information-leaking functions could be executed on the leftover rows, in addition to the visibly updated or deleted row. Fix by having ExecInsert() skip RETURNING processing when it is handling an internal FOR PORTION OF leftover insert. Use both the presence of a FOR PORTION OF clause and mtstate->operation == CMD_INSERT for this check, so that the auxiliary INSERT of a cross-partition UPDATE with a FOR PORTION OF clause still processes RETURNING normally. Back-patch to v19, where support for FOR PORTION OF was added. Author: Chao Li <lic@highgo.com> Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com> Reviewed-by: Paul A Jungwirth <pj@illuminatedcomputing.com> Discussion: https://postgr.es/m/07C125E5-F6ED-460C-A394-E6503DAE18FB@gmail.com Backpatch-through: 19 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/62d1a5f8be836faa5547789fe19d34bac1b908f4 Modified Files -------------- src/backend/executor/nodeModifyTable.c | 14 +++++++++-- src/test/regress/expected/for_portion_of.out | 36 +++++++++++++++++++++------- src/test/regress/sql/for_portion_of.sql | 16 ++++++++++--- 3 files changed, 52 insertions(+), 14 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Avoid RETURNING side effects for FOR PORTION OF leftovers. @ 2026-07-28 08:48 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 2+ messages in thread From: Dean Rasheed @ 2026-07-28 08:48 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid RETURNING side effects for FOR PORTION OF leftovers. UPDATE/DELETE ... FOR PORTION OF inserts leftover rows for the untouched parts of the original row. These hidden inserts should not affect the command tag or ROW_COUNT, so they call ExecInsert() with canSetTag set to false. However, ExecInsert() still processed the RETURNING list whenever the target ResultRelInfo had ri_projectReturning set. That caused RETURNING expressions to be evaluated for leftover rows even though their results were discarded. As a result, expressions with side effects and information-leaking functions could be executed on the leftover rows, in addition to the visibly updated or deleted row. Fix by having ExecInsert() skip RETURNING processing when it is handling an internal FOR PORTION OF leftover insert. Use both the presence of a FOR PORTION OF clause and mtstate->operation == CMD_INSERT for this check, so that the auxiliary INSERT of a cross-partition UPDATE with a FOR PORTION OF clause still processes RETURNING normally. Back-patch to v19, where support for FOR PORTION OF was added. Author: Chao Li <lic@highgo.com> Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com> Reviewed-by: Paul A Jungwirth <pj@illuminatedcomputing.com> Discussion: https://postgr.es/m/07C125E5-F6ED-460C-A394-E6503DAE18FB@gmail.com Backpatch-through: 19 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/fd92f74b91d079430ef4544713a90b7b6aa8faee Modified Files -------------- src/backend/executor/nodeModifyTable.c | 14 +++++++++-- src/test/regress/expected/for_portion_of.out | 36 +++++++++++++++++++++------- src/test/regress/sql/for_portion_of.sql | 16 ++++++++++--- 3 files changed, 52 insertions(+), 14 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-07-28 08:48 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-07-28 08:48 pgsql: Avoid RETURNING side effects for FOR PORTION OF leftovers. Dean Rasheed <dean.a.rasheed@gmail.com> 2026-07-28 08:48 pgsql: Avoid RETURNING side effects for FOR PORTION OF leftovers. Dean Rasheed <dean.a.rasheed@gmail.com>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox