Fix heap_update() ignoring TABLE_UPDATE_NO_LOGICAL for TOAST tuples.

Previously, heap_update() honored TABLE_UPDATE_NO_LOGICAL for the main
tuple but passed a hardcoded 0 to the tuple toaster, so the tuples it
wrote to the TOAST relation were logged for decoding anyway. That was
harmless until commit 28d534e2ae0a gave updates the flag; the insert
path has propagated its own ever since suppression was introduced for
heap rewrites.

REPACK (CONCURRENTLY), the only user of the flag, relies on it to keep
the changes it applies to the transient heap out of the logical
stream. Logical decoding therefore reassembled the TOAST value and
then dereferenced a new tuple that the suppressed record doesn't
carry, crashing the backend. This is reachable only if an output
plugin asks for the changes made by heap rewrites. In core that is
just test_decoding with include-rewrites.

Fix this by passing HEAP_INSERT_NO_LOGICAL down to the tuple toaster
when TABLE_UPDATE_NO_LOGICAL is set.

Backpatch to v19, where REPACK (CONCURRENTLY) was introduced.

Reported-by: Thom Brown <[email protected]>
Author: Antonin Houska <[email protected]>
Reviewed-by: Masahiko Sawada <[email protected]>
Reviewed-by: Zhijie Hou (Fujitsu) <[email protected]>
Reviewed-by: Álvaro Herrera <[email protected]>
Discussion: 
https://postgr.es/m/CAA-aLv7L_-dOuHXjLh0Di66dExdOb=uTOzR=jtrqcmv0wxy...@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/741f9d741e6dd9bc9174e4f522fc65b87b8d5ee3

Modified Files
--------------
src/backend/access/heap/heapam.c                   |  8 ++-
src/test/modules/injection_points/Makefile         |  3 ++
.../injection_points/expected/repack_decode.out    | 36 +++++++++++++
src/test/modules/injection_points/meson.build      |  1 +
.../injection_points/specs/repack_decode.spec      | 60 ++++++++++++++++++++++
5 files changed, 106 insertions(+), 2 deletions(-)

Reply via email to