Re: WIP patch for latestCompletedXid method of computing snapshot xmax

From: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: WIP patch for latestCompletedXid method of computing snapshot xmax
Date: 2007-09-09 22:52:04
Message-ID: 46E47914.8000504@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> "Florian G. Pflug" <fgp(at)phlo(dot)org> writes:
>> This guarantee enables a few optimizations. First, as you say in the
>> comments, finding the largest xid when committing becomes trivial. But more
>> important, if we can assume that the proc array xid cache is always
>> sorted, we can get ride of the exclusive lock during subxact abort.
>
> No, we can't, because subxact abort still has to advance latestCompletedXid.

I don't think so. I didn't notice that when initially reading your patch -
but it seems that updating latestCompletedXid during subxact abort is actually
worsening performance (only very slightly, though).

The whole point of updating latestCompletedXid when aborting a toplevel xact
is to prevent the following corner case.
.) Some transaction commits
.) Only readonly transactions
(all xmins = xmaxs = latestCompletedXid+1)
.) One large Transaction that Aborts
(xid = GetNewTransactionId() = latestCompletedXid+1)
.) Only readonly transactions for a long period again.
all xmins = xmaxs = latestCompletedXid+1

If the ABORT didn't update latestCompletedXid, than we'd not be able to remove
rows created by that one large transactions (which aborted), because all the
xmins would still be latestCompletedXid+1, which is not > the xid of the
aborted transaction.

So we updating latestCompletedXid is only *necessary* durings COMMITS - during
ABORTS it's just done for efficiency reasons.

But for subtransactions, there is no efficiency gain at all, because the
toplevel xid already bounds the xmin. In fact, updating latestCompletedXid
during subxact moves the snapshot's xmax unnecessary far into the future,
which leads to larger snasphots, meaning more cycles spent to scan them.

I do feel that I explained the idea rather badly though in my initial
response to your patch - I'll post (hopefully) better explanation to
the hackers list shortly.

greetings, Florian Pflug

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Florian G. Pflug 2007-09-09 23:50:05 Maybe some more low-hanging fruit in the latestCompletedXid patch.
Previous Message Andrew Dunstan 2007-09-09 22:07:38 Re: invalidly encoded strings

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2007-09-10 03:22:26 Re: invalidly encoded strings
Previous Message Andrew Dunstan 2007-09-09 22:07:38 Re: invalidly encoded strings