pgsql: Speed up HeapTupleSatisfiesMVCC() by replacing the XID-in-progre

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Speed up HeapTupleSatisfiesMVCC() by replacing the XID-in-progre
Date: 2015-08-26 22:19:20
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

Speed up HeapTupleSatisfiesMVCC() by replacing the XID-in-progress test.

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.



Modified Files
src/backend/utils/time/tqual.c | 108 ++++++++++++++++++++++++----------------
1 file changed, 66 insertions(+), 42 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2015-08-27 16:22:17 pgsql: Add a small cache of locks owned by a resource owner in Resource
Previous Message Bruce Momjian 2015-08-26 18:46:57 pgsql: release notes: abbreviated key speedup only for varchar/text