Change tqual.c tests to use !TransactionIdIsCurrentTransactionId, rather than
authorTom Lane
Fri, 21 Sep 2007 18:24:28 +0000 (18:24 +0000)
committerTom Lane
Fri, 21 Sep 2007 18:24:28 +0000 (18:24 +0000)
TransactionIdDidAbort, when handling the case that xmin is one of the current
transaction's XIDs and the tuple has been deleted.  xmax must also be one of
the current transaction's XIDs, since no one else can see it yet, and it's
cheaper to look at local state than shared state to find out if xmax aborted.
Per an idea of Heikki's.

src/backend/utils/time/tqual.c

index f580c0b461250a589134ca9929c8a43e63be443d..e5401861455af67bf42d675618f30d280d4951ff 100644 (file)
@@ -31,7 +31,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/time/tqual.c,v 1.105 2007/09/08 20:31:15 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/time/tqual.c,v 1.106 2007/09/21 18:24:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -219,16 +219,14 @@ HeapTupleSatisfiesSelf(HeapTupleHeader tuple, Snapshot snapshot, Buffer buffer)
 
            Assert(!(tuple->t_infomask & HEAP_XMAX_IS_MULTI));
 
-           /* deleting subtransaction aborted? */
-           if (TransactionIdDidAbort(HeapTupleHeaderGetXmax(tuple)))
+           if (!TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmax(tuple)))
            {
+               /* deleting subtransaction must have aborted */
                SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
                            InvalidTransactionId);
                return true;
            }
 
-           Assert(TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmax(tuple)));
-
            return false;
        }
        else if (TransactionIdIsInProgress(HeapTupleHeaderGetXmin(tuple)))
@@ -395,16 +393,14 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple, Snapshot snapshot, Buffer buffer)
 
            Assert(!(tuple->t_infomask & HEAP_XMAX_IS_MULTI));
 
-           /* deleting subtransaction aborted? */
-           if (TransactionIdDidAbort(HeapTupleHeaderGetXmax(tuple)))
+           if (!TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmax(tuple)))
            {
+               /* deleting subtransaction must have aborted */
                SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
                            InvalidTransactionId);
                return true;
            }
 
-           Assert(TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmax(tuple)));
-
            if (HeapTupleHeaderGetCmax(tuple) >= GetCurrentCommandId())
                return true;    /* deleted after scan started */
            else
@@ -640,16 +636,14 @@ HeapTupleSatisfiesUpdate(HeapTupleHeader tuple, CommandId curcid,
 
            Assert(!(tuple->t_infomask & HEAP_XMAX_IS_MULTI));
 
-           /* deleting subtransaction aborted? */
-           if (TransactionIdDidAbort(HeapTupleHeaderGetXmax(tuple)))
+           if (!TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmax(tuple)))
            {
+               /* deleting subtransaction must have aborted */
                SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
                            InvalidTransactionId);
                return HeapTupleMayBeUpdated;
            }
 
-           Assert(TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmax(tuple)));
-
            if (HeapTupleHeaderGetCmax(tuple) >= curcid)
                return HeapTupleSelfUpdated;    /* updated after scan started */
            else
@@ -806,16 +800,14 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple, Snapshot snapshot,
 
            Assert(!(tuple->t_infomask & HEAP_XMAX_IS_MULTI));
 
-           /* deleting subtransaction aborted? */
-           if (TransactionIdDidAbort(HeapTupleHeaderGetXmax(tuple)))
+           if (!TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmax(tuple)))
            {
+               /* deleting subtransaction must have aborted */
                SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
                            InvalidTransactionId);
                return true;
            }
 
-           Assert(TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmax(tuple)));
-
            return false;
        }
        else if (TransactionIdIsInProgress(HeapTupleHeaderGetXmin(tuple)))
@@ -970,17 +962,14 @@ HeapTupleSatisfiesMVCC(HeapTupleHeader tuple, Snapshot snapshot,
 
            Assert(!(tuple->t_infomask & HEAP_XMAX_IS_MULTI));
 
-           /* deleting subtransaction aborted? */
-           /* FIXME -- is this correct w.r.t. the cmax of the tuple? */
-           if (TransactionIdDidAbort(HeapTupleHeaderGetXmax(tuple)))
+           if (!TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmax(tuple)))
            {
+               /* deleting subtransaction must have aborted */
                SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
                            InvalidTransactionId);
                return true;
            }
 
-           Assert(TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmax(tuple)));
-
            if (HeapTupleHeaderGetCmax(tuple) >= snapshot->curcid)
                return true;    /* deleted after scan started */
            else