mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Make TransactionIdIsInProgress check transam.c's single-item XID status cache
before it goes groveling through the ProcArray. In situations where the same recently-committed transaction ID is checked repeatedly by tqual.c, this saves a lot of shared-memory searches. And it's cheap enough that it shouldn't hurt noticeably when it doesn't help. Concept and patch by Simon, some minor tweaking and comment-cleanup by Tom.
This commit is contained in:
@ -23,7 +23,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.40 2008/01/09 21:52:36 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.41 2008/03/11 20:20:35 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -60,6 +60,7 @@ static ProcArrayStruct *procArray;
|
||||
|
||||
/* counters for XidCache measurement */
|
||||
static long xc_by_recent_xmin = 0;
|
||||
static long xc_by_known_xact = 0;
|
||||
static long xc_by_my_xact = 0;
|
||||
static long xc_by_latest_xid = 0;
|
||||
static long xc_by_main_xid = 0;
|
||||
@ -68,6 +69,7 @@ static long xc_no_overflow = 0;
|
||||
static long xc_slow_answer = 0;
|
||||
|
||||
#define xc_by_recent_xmin_inc() (xc_by_recent_xmin++)
|
||||
#define xc_by_known_xact_inc() (xc_by_known_xact++)
|
||||
#define xc_by_my_xact_inc() (xc_by_my_xact++)
|
||||
#define xc_by_latest_xid_inc() (xc_by_latest_xid++)
|
||||
#define xc_by_main_xid_inc() (xc_by_main_xid++)
|
||||
@ -79,6 +81,7 @@ static void DisplayXidCache(void);
|
||||
#else /* !XIDCACHE_DEBUG */
|
||||
|
||||
#define xc_by_recent_xmin_inc() ((void) 0)
|
||||
#define xc_by_known_xact_inc() ((void) 0)
|
||||
#define xc_by_my_xact_inc() ((void) 0)
|
||||
#define xc_by_latest_xid_inc() ((void) 0)
|
||||
#define xc_by_main_xid_inc() ((void) 0)
|
||||
@ -353,6 +356,17 @@ TransactionIdIsInProgress(TransactionId xid)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* We may have just checked the status of this transaction, so if it is
|
||||
* already known to be completed, we can fall out without any access to
|
||||
* shared memory.
|
||||
*/
|
||||
if (TransactionIdIsKnownCompleted(xid))
|
||||
{
|
||||
xc_by_known_xact_inc();
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Also, we can handle our own transaction (and subtransactions) without
|
||||
* any access to shared memory.
|
||||
@ -1335,8 +1349,9 @@ static void
|
||||
DisplayXidCache(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"XidCache: xmin: %ld, myxact: %ld, latest: %ld, mainxid: %ld, childxid: %ld, nooflo: %ld, slow: %ld\n",
|
||||
"XidCache: xmin: %ld, known: %ld, myxact: %ld, latest: %ld, mainxid: %ld, childxid: %ld, nooflo: %ld, slow: %ld\n",
|
||||
xc_by_recent_xmin,
|
||||
xc_by_known_xact,
|
||||
xc_by_my_xact,
|
||||
xc_by_latest_xid,
|
||||
xc_by_main_xid,
|
||||
|
Reference in New Issue
Block a user