• Tom Lane's avatar
    Speed up HeapTupleSatisfiesMVCC() by replacing the XID-in-progress test. · 8a7d0701
    Tom Lane authored
    Rather than consulting TransactionIdIsInProgress to see if an in-doubt
    transaction is still running, consult XidInMVCCSnapshot.  That requires
    the same or fewer cycles as TransactionIdIsInProgress, and what's far
    more important, it does not access shared data structures (at least in the
    no-subxip-overflow case) so it incurs no contention.  Furthermore, we would
    have had to check XidInMVCCSnapshot anyway before deciding that we were
    allowed to see the tuple.
    
    There should never be a case where XidInMVCCSnapshot says a transaction is
    done while TransactionIdIsInProgress says it's still running.  The other
    way around is quite possible though.  The result of that difference is that
    HeapTupleSatisfiesMVCC will no longer set hint bits on tuples whose source
    transactions recently finished but are still running according to our
    snapshot.  The main cost of delaying the hint-bit setting is that repeated
    visits to a just-committed tuple, by transactions none of which have
    snapshots new enough to see the source transaction as done, will each
    execute TransactionIdIsCurrentTransactionId, which they need not have done
    before.  However, that's normally just a small overhead, and no contention
    costs are involved; so it seems well worth the benefit of removing
    TransactionIdIsInProgress calls during the life of the source transaction.
    
    The core idea for this patch is due to Jeff Janes, who also did the legwork
    proving its performance benefits.  His original proposal was to swap the
    order of TransactionIdIsInProgress and XidInMVCCSnapshot calls in some
    cases within HeapTupleSatisfiesMVCC.  That was a bit messy though.
    The idea that we could dispense with calling TransactionIdIsInProgress
    altogether was mine, as is the final patch.
    8a7d0701
tqual.c 52.9 KB