On Mon, Jun 24, 2024 at 4:42 PM Peter Geoghegan <p...@bowt.ie> wrote: > > On Mon, Jun 24, 2024 at 3:36 PM Melanie Plageman > <melanieplage...@gmail.com> wrote: > > One thing I don't understand is why it is okay to freeze the xmax of a > > dead tuple just because it is from an aborted update. > > We don't do that with XID-based xmaxs. Though perhaps we should, since > we'll already prune-away the successor tuple, and so might as well go > one tiny step further and clear the xmax for the original tuple via > freezing/setting it InvalidTransactionId. Instead we just leave the > original tuple largely undisturbed, with its original xmax.
I thought that was the case too, but we call heap_prepare_freeze_tuple() on HEAPTUPLE_RECENTLY_DEAD tuples and then else if (TransactionIdIsNormal(xid)) { /* Raw xmax is normal XID */ freeze_xmax = TransactionIdPrecedes(xid, cutoffs->OldestXmin); } And then later we if (freeze_xmax) frz->xmax = InvalidTransactionId; and then when we execute freezing the tuple in heap_execute_freeze_tuple() HeapTupleHeaderSetXmax(tuple, frz->xmax); Which sets the xmax to InvalidTransactionId. Or am I missing something? > > The only case in which we freeze dead tuples > > with a non-multi xmax is if the xmax is from before OldestXmin and is > > also not committed (so from an aborted update). > > Perhaps I misunderstand, but: we simply don't freeze DEAD (not > RECENTLY_DEAD) tuples in the first place, because we don't have to > (pruning removes them instead). It doesn't matter if they're DEAD due > to being from aborted transactions or DEAD due to being > deleted/updated by a transaction that committed (committed and < > OldestXmin). Right, I'm talking about HEAPTUPLE_RECENTLY_DEAD tuples. HEAPTUPLE_DEAD tuples are pruned away. But we can't replace the xmax of a tuple that has been deleted or updated by a transaction that committed with InvalidTransactionId. And it seems like the code does that? Why even call heap_prepare_freeze_tuple() on HEAPTUPLE_RECENTLY_DEAD tuples? Is it mainly to handle MultiXact freezing? > The freezing related code paths in heapam.c don't particularly care > whether a tuple xmax is RECENTLY_DEAD or LIVE to HTSV + OldestXmin. > Just as long as it's not fully DEAD (then it should have been pruned). But it just seems like we shouldn't freeze RECENTLY_DEAD either. - Melanie