Missed opportunity for bsearch() in TransactionIdIsCurrentTransactionId()? - Mailing list pgsql-hackers

From Antonin Houska
Subject Missed opportunity for bsearch() in TransactionIdIsCurrentTransactionId()?
Date
Msg-id 36977.1720623613@antos
Whole thread Raw
Responses Re: Missed opportunity for bsearch() in TransactionIdIsCurrentTransactionId()?
List pgsql-hackers
I don't quite understand why TransactionIdIsCurrentTransactionId() implements
binary search in ParallelCurrentXids "from scratch" instead of using
bsearch().

If I read the code correctly, the contents of the ParallelCurrentXids is
composed in SerializeTransactionState(), which uses xidComparator:

    qsort(workspace, nxids, sizeof(TransactionId), xidComparator);

so it should be o.k. to use bsearch(..., xidComparator).

For example, ReorderBufferCopySnap() also uses xidComparator to sort the
'subxip' array, and HeapTupleSatisfiesHistoricMVCC() then uses
TransactionIdInArray() (which is effectively bsearch(..., xidComparator)) to
search for particular XID in the array.

-- 
Antonin Houska
Web: https://www.cybertec-postgresql.com


Attachment

pgsql-hackers by date:

Previous
From: "David E. Wheeler"
Date:
Subject: Re: jsonpath: Inconsistency of timestamp_tz() Output
Next
From: "David G. Johnston"
Date:
Subject: Re: Is it possible to create a cursor with hold using extended query protocol