pgsql: Avoid RETURNING side effects for FOR PORTION OF leftovers. - Mailing list pgsql-committers

From Dean Rasheed
Subject pgsql: Avoid RETURNING side effects for FOR PORTION OF leftovers.
Date
Msg-id E1wodU0-00000000d2I-3CLw@gemulon.postgresql.org
Whole thread
List pgsql-committers
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(-)


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: Fix propagation of indimmediate flag in index_create_copy()
Next
From: Masahiko Sawada
Date:
Subject: pgsql: Fix pg_get_publication_tables() failure with concurrent DROP TAB