Re: Optimizing TransactionIdIsCurrentTransactionId()

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Optimizing TransactionIdIsCurrentTransactionId()
Date: 2019-12-20 05:46:43
Message-ID: CANP8+jKzMEBLkSpCAKeny7ahq5JR2uyV1Xs4UtV5JEyRqNuU+w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 19 Dec 2019 at 19:27, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

> On Wed, Dec 18, 2019 at 5:07 AM Simon Riggs <simon(at)2ndquadrant(dot)com> wrote:
> > TransactionIdIsCurrentTransactionId() doesn't seem to be well optimized
> for the case when an xid has not yet been assigned, so for read only
> transactions.
> >
> > A patch for this is attached.
>
> It might be an idea to first call TransactionIdIsNormal(xid), then
> GetTopTransactionIdIfAny(), then TransactionIdIsNormal(topxid), so
> that we don't bother with GetTopTransactionIdIfAny() when
> !TransactionIdIsNormal(xid).
>
> But it's also not clear to me whether this is actually a win. You're
> dong an extra TransactionIdIsNormal() test to sometimes avoid a
> GetTopTransactionIdIfAny() test.

That's not the point of the patch.

If the TopTransactionId is not assigned, we can leave the whole function
more quickly, not just avoid a test.

Read only transactions should have a fast path thru this function since
they frequently read more data than write transactions.

--
Simon Riggs http://www.2ndQuadrant.com/
<http://www.2ndquadrant.com/>
PostgreSQL Solutions for the Enterprise

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2019-12-20 05:55:10 pgsql: Superuser can permit passwordless connections on postgres_fdw
Previous Message Andrey Borodin 2019-12-20 05:03:57 Disallow cancellation of waiting for synchronous replication