diff options
author | Michael Paquier <michael@paquier.xyz> | 2022-09-22 09:47:28 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2022-09-22 09:47:28 +0900 |
commit | 14ff44f80c09718d43d853363941457f5468cc03 (patch) | |
tree | 4d948813b488f91c9142211776fcf7e61169a134 /src | |
parent | 9a6915257d1d804ddba05331030b74d7426a4005 (diff) | |
download | postgresql-14ff44f80c09718d43d853363941457f5468cc03.tar.gz postgresql-14ff44f80c09718d43d853363941457f5468cc03.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/storage/ipc/procarray.c | 12 | ||||
-rw-r--r-- | src/backend/storage/lmgr/predicate.c | 10 |
2 files changed, 6 insertions, 16 deletions
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 382f4cfb736..207c4b27fdf 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -58,6 +58,7 @@ #include "commands/dbcommands.h" #include "miscadmin.h" #include "pgstat.h" +#include "port/pg_lfind.h" #include "storage/proc.h" #include "storage/procarray.h" #include "storage/spin.h" @@ -1586,14 +1587,9 @@ TransactionIdIsInProgress(TransactionId xid) */ topxid = SubTransGetTopmostTransaction(xid); Assert(TransactionIdIsValid(topxid)); - if (!TransactionIdEquals(topxid, xid)) - { - for (int i = 0; i < nxids; i++) - { - if (TransactionIdEquals(xids[i], topxid)) - return true; - } - } + if (!TransactionIdEquals(topxid, xid) && + pg_lfind32(topxid, xids, nxids)) + return true; cachedXidIsNotInProgress = xid; return false; diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c index 5f2a4805d82..e8120174d61 100644 --- a/src/backend/storage/lmgr/predicate.c +++ b/src/backend/storage/lmgr/predicate.c @@ -202,6 +202,7 @@ #include "access/xlog.h" #include "miscadmin.h" #include "pgstat.h" +#include "port/pg_lfind.h" #include "storage/bufmgr.h" #include "storage/predicate.h" #include "storage/predicate_internals.h" @@ -4065,7 +4066,6 @@ static bool XidIsConcurrent(TransactionId xid) { Snapshot snap; - uint32 i; Assert(TransactionIdIsValid(xid)); Assert(!TransactionIdEquals(xid, GetTopTransactionIdIfAny())); @@ -4078,13 +4078,7 @@ XidIsConcurrent(TransactionId xid) if (TransactionIdFollowsOrEquals(xid, snap->xmax)) return true; - for (i = 0; i < snap->xcnt; i++) - { - if (xid == snap->xip[i]) - return true; - } - - return false; + return pg_lfind32(xid, snap->xip, snap->xcnt); } bool |