Fix data loss at inplace update after heap_update().
authorNoah Misch <[email protected]>
Tue, 24 Sep 2024 22:25:18 +0000 (15:25 -0700)
committerNoah Misch <[email protected]>
Tue, 24 Sep 2024 22:25:24 +0000 (15:25 -0700)
commita8ad1929d2ec04a5e46dd51d2ef5768c7179ef0b
treed45e0095bcea1bbd4d3042c23bd8ce885a30a5ee
parent5ef9b4a2f79670a1cf9649e568fba7920a72e9a4
Fix data loss at inplace update after heap_update().

As previously-added tests demonstrated, heap_inplace_update() could
instead update an unrelated tuple of the same catalog.  It could lose
the update.  Losing relhasindex=t was a source of index corruption.
Inplace-updating commands like VACUUM will now wait for heap_update()
commands like GRANT TABLE and GRANT DATABASE.  That isn't ideal, but a
long-running GRANT already hurts VACUUM progress more just by keeping an
XID running.  The VACUUM will behave like a DELETE or UPDATE waiting for
the uncommitted change.

For implementation details, start at the systable_inplace_update_begin()
header comment and README.tuplock.  Back-patch to v12 (all supported
versions).  In back branches, retain a deprecated heap_inplace_update(),
for extensions.

Reported by Smolkin Grigory.  Reviewed by Nitin Motiani, (in earlier
versions) Heikki Linnakangas, and (in earlier versions) Alexander
Lakhin.

Discussion: https://postgr.es/m/CAMp+ueZQz3yDk7qg42hk6-9gxniYbp-=bG2mgqecErqR5gGGOA@mail.gmail.com
13 files changed:
src/backend/access/heap/README.tuplock
src/backend/access/heap/heapam.c
src/backend/access/index/genam.c
src/backend/catalog/index.c
src/backend/catalog/toasting.c
src/backend/commands/dbcommands.c
src/backend/commands/vacuum.c
src/include/access/genam.h
src/include/access/heapam.h
src/test/isolation/expected/intra-grant-inplace-db.out
src/test/isolation/expected/intra-grant-inplace.out
src/test/isolation/specs/intra-grant-inplace-db.spec
src/test/isolation/specs/intra-grant-inplace.spec