From 386a5d4268c7ae13510f0a40243b2277eccb6189 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 21 Sep 2007 18:24:28 +0000 Subject: [PATCH] Change tqual.c tests to use !TransactionIdIsCurrentTransactionId, rather than 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 | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c index f580c0b461..e540186145 100644 --- a/src/backend/utils/time/tqual.c +++ b/src/backend/utils/time/tqual.c @@ -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