Skip to content

Commit 9a57858

Browse files
committed
Fix WAL replay of locking an updated tuple
We were resetting the tuple's HEAP_HOT_UPDATED flag as well as t_ctid on WAL replay of a tuple-lock operation, which is incorrect when the tuple is already updated. Back-patch to 9.3. The clearing of both header elements was there previously, but since no update could be present on a tuple that was being locked, it was harmless. Bug reported by Peter Geoghegan and Greg Stark in CAM3SWZTMQiCi5PV5OWHb+bYkUcnCk=O67w0cSswPvV7XfUcU5g@mail.gmail.com and CAM-w4HPTOeMT4KP0OJK+mGgzgcTOtLRTvFZyvD0O4aH-7dxo3Q@mail.gmail.com respectively; diagnosis by Andres Freund.
1 parent 4162a55 commit 9a57858

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/backend/access/heap/heapam.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7721,11 +7721,19 @@ heap_xlog_lock(XLogRecPtr lsn, XLogRecord *record)
77217721

77227722
fix_infomask_from_infobits(xlrec->infobits_set, &htup->t_infomask,
77237723
&htup->t_infomask2);
7724-
HeapTupleHeaderClearHotUpdated(htup);
7724+
7725+
/*
7726+
* Clear relevant update flags, but only if the modified infomask says
7727+
* there's no update.
7728+
*/
7729+
if (HEAP_XMAX_IS_LOCKED_ONLY(htup->t_infomask))
7730+
{
7731+
HeapTupleHeaderClearHotUpdated(htup);
7732+
/* Make sure there is no forward chain link in t_ctid */
7733+
htup->t_ctid = xlrec->target.tid;
7734+
}
77257735
HeapTupleHeaderSetXmax(htup, xlrec->locking_xid);
77267736
HeapTupleHeaderSetCmax(htup, FirstCommandId, false);
7727-
/* Make sure there is no forward chain link in t_ctid */
7728-
htup->t_ctid = xlrec->target.tid;
77297737
PageSetLSN(page, lsn);
77307738
MarkBufferDirty(buffer);
77317739
UnlockReleaseBuffer(buffer);

0 commit comments

Comments
 (0)