Fix relation statistics around transactional TRUNCATE
Thread notes
1 note#bug
hackorum-bot#bug
@global #bug
Hi hackers,
While reviewing [1]/messages/by-id/avwEcRxMmL7o/hfm@bdtpg, I noticed that n_ins_since_vacuum can incorrectly retain
inserts performed before a committed TRUNCATE.
While preparing a fix, I found similar problems with n_dead_tup: committing or
aborting a TRUNCATE can retain counts belonging to the wrong relfilenode.
PFA 4 patches to $SUBJECT:
0001 fixes n_ins_since_vacuum for regular transactions (oversight in b07642dbcd8d)
0002 adds the corresponding 2PC handling.
0003 fixes n_dead_tup for regular transactions (oversight in d42358efb16)
0004 adds the corresponding 2PC handling.
The 2PC cases require storing both the current and pre-TRUNCATE counts:
COMMIT PREPARED uses the former, while ROLLBACK PREPARED restores the latter.
Since prepared transactions can survive a minor upgrade, recovery accepts both
record formats and distinguishes them by length. Both 2PC changes are intended
for the same minor release, so no intermediate format needs to be supported.
I propose adapting and backpatching them through 15. On the back branches, I think
that the new PgStat_Counter fields should be appended to the older structures (
PgStat_TableCounts and PgStat_TableXactStatus) to preserve existing member offsets.
[1]: /messages/by-id/avwEcRxMmL7o/hfm@bdtpg
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com