]> granicus.if.org Git - postgresql/commitdiff
Fix old visibility bug in HeapTupleSatisfiesDirty
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 2 Aug 2013 18:34:56 +0000 (14:34 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 2 Aug 2013 21:07:32 +0000 (17:07 -0400)
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

src/backend/utils/time/tqual.c

index 94e40c69ae8b9431ffc8aa26208d7aebe0d4d731..c0b8970ff819d49c7ce8ad0d8dc48635aa4555a7 100644 (file)
@@ -848,7 +848,8 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple, Snapshot snapshot,
 
        if (TransactionIdIsInProgress(HeapTupleHeaderGetXmax(tuple)))
        {
-               snapshot->xmax = HeapTupleHeaderGetXmax(tuple);
+               if (!(tuple->t_infomask & HEAP_IS_LOCKED))
+                       snapshot->xmax = HeapTupleHeaderGetXmax(tuple);
                return true;
        }