pgsql: Fix heap_update() ignoring TABLE_UPDATE_NO_LOGICAL for TOAST tup

From: Masahiko Sawada <msawada(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix heap_update() ignoring TABLE_UPDATE_NO_LOGICAL for TOAST tup
Date: 2026-09-11 17:21:56
Message-ID: E1x54wl-00000004SmR-33ck@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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 <thom(at)linux(dot)com>
Author: Antonin Houska <ah(at)cybertec(dot)at>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Reviewed-by: Zhijie Hou (Fujitsu) <houzj(dot)fnst(at)fujitsu(dot)com>
Reviewed-by: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Discussion: https://postgr.es/m/CAA-aLv7L_-dOuHXjLh0Di66dExdOb=uTOzR=jtrqCmV0Wxyd2Q@mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7164dcb6653242f757b5bdc4a26714a24207b1db

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Masahiko Sawada 2026-09-11 17:22:01 pgsql: Fix heap_update() ignoring TABLE_UPDATE_NO_LOGICAL for TOAST tup
Previous Message Peter Eisentraut 2026-09-11 16:00:43 pgsql: Remove unused global variables