mirror of
https://github.com/postgres/postgres.git
synced 2025-06-05 23:56:58 +03:00
Used optimized linear search in more code paths
This commit updates two code paths to use pg_lfind32() introduced by b6ef167 with TransactionId arrays: - At the end of TransactionIdIsInProgress(), when checking for the case of still running but overflowed subxids. - XidIsConcurrent(), when checking for a serializable conflict. These cases are less impactful than 37a6e5d, but a bit of micro-benchmarking of this API shows that linear search speeds up by ~20% depending on the number of items involved (x86_64 and amd64 looked at here). Author: Nathan Bossart Reviewed-by: Richard Guo, Michael Paquier Discussion: https://postgr.es/m/20220901185153.GA783106@nathanxps13
This commit is contained in:
parent
9a6915257d
commit
14ff44f80c
@ -58,6 +58,7 @@
|
|||||||
#include "commands/dbcommands.h"
|
#include "commands/dbcommands.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
#include "pgstat.h"
|
#include "pgstat.h"
|
||||||
|
#include "port/pg_lfind.h"
|
||||||
#include "storage/proc.h"
|
#include "storage/proc.h"
|
||||||
#include "storage/procarray.h"
|
#include "storage/procarray.h"
|
||||||
#include "storage/spin.h"
|
#include "storage/spin.h"
|
||||||
@ -1586,14 +1587,9 @@ TransactionIdIsInProgress(TransactionId xid)
|
|||||||
*/
|
*/
|
||||||
topxid = SubTransGetTopmostTransaction(xid);
|
topxid = SubTransGetTopmostTransaction(xid);
|
||||||
Assert(TransactionIdIsValid(topxid));
|
Assert(TransactionIdIsValid(topxid));
|
||||||
if (!TransactionIdEquals(topxid, xid))
|
if (!TransactionIdEquals(topxid, xid) &&
|
||||||
{
|
pg_lfind32(topxid, xids, nxids))
|
||||||
for (int i = 0; i < nxids; i++)
|
return true;
|
||||||
{
|
|
||||||
if (TransactionIdEquals(xids[i], topxid))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cachedXidIsNotInProgress = xid;
|
cachedXidIsNotInProgress = xid;
|
||||||
return false;
|
return false;
|
||||||
|
@ -202,6 +202,7 @@
|
|||||||
#include "access/xlog.h"
|
#include "access/xlog.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
#include "pgstat.h"
|
#include "pgstat.h"
|
||||||
|
#include "port/pg_lfind.h"
|
||||||
#include "storage/bufmgr.h"
|
#include "storage/bufmgr.h"
|
||||||
#include "storage/predicate.h"
|
#include "storage/predicate.h"
|
||||||
#include "storage/predicate_internals.h"
|
#include "storage/predicate_internals.h"
|
||||||
@ -4065,7 +4066,6 @@ static bool
|
|||||||
XidIsConcurrent(TransactionId xid)
|
XidIsConcurrent(TransactionId xid)
|
||||||
{
|
{
|
||||||
Snapshot snap;
|
Snapshot snap;
|
||||||
uint32 i;
|
|
||||||
|
|
||||||
Assert(TransactionIdIsValid(xid));
|
Assert(TransactionIdIsValid(xid));
|
||||||
Assert(!TransactionIdEquals(xid, GetTopTransactionIdIfAny()));
|
Assert(!TransactionIdEquals(xid, GetTopTransactionIdIfAny()));
|
||||||
@ -4078,13 +4078,7 @@ XidIsConcurrent(TransactionId xid)
|
|||||||
if (TransactionIdFollowsOrEquals(xid, snap->xmax))
|
if (TransactionIdFollowsOrEquals(xid, snap->xmax))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
for (i = 0; i < snap->xcnt; i++)
|
return pg_lfind32(xid, snap->xip, snap->xcnt);
|
||||||
{
|
|
||||||
if (xid == snap->xip[i])
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
Loading…
x
Reference in New Issue
Block a user