From: Alvaro Herrera Date: Fri, 2 Aug 2013 18:34:56 +0000 (-0400) Subject: Fix old visibility bug in HeapTupleSatisfiesDirty X-Git-Tag: REL9_3_RC1~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=69fdc9577b09dce732153c33c2484dac7d506ad9;p=postgresql Fix old visibility bug in HeapTupleSatisfiesDirty If a tuple is locked but not updated by a concurrent transaction, HeapTupleSatisfiesDirty would return that transaction's Xid in xmax, causing callers to wait on it, when it is not necessary (in fact, if the other transaction had used a multixact instead of a plain Xid to mark the tuple, HeapTupleSatisfiesDirty would have behave differently and *not* returned the Xmax). This bug was introduced in commit 3f7fbf85dc5b42, dated December 1998, so it's almost 15 years old now. However, it's hard to see this misbehave, because before we had NOWAIT the only consequence of this is that transactions would wait for slightly more time than necessary; so it's not surprising that this hasn't been reported yet. Craig Ringer and Andres Freund --- diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c index c69ffd306e..70923bd4ac 100644 --- a/src/backend/utils/time/tqual.c +++ b/src/backend/utils/time/tqual.c @@ -992,7 +992,8 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple, Snapshot snapshot, if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmax(tuple))) { - snapshot->xmax = HeapTupleHeaderGetRawXmax(tuple); + if (!HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask)) + snapshot->xmax = HeapTupleHeaderGetRawXmax(tuple); return true; }