Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 387CD9F97B7 for ; Sun, 9 Sep 2007 19:52:16 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 85625-06 for ; Sun, 9 Sep 2007 19:52:01 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from master.phlo.org (master.phlo.org [213.147.174.89]) by postgresql.org (Postfix) with ESMTP id 013619F979A for ; Sun, 9 Sep 2007 19:52:04 -0300 (ADT) Received: (qmail 7358 invoked by uid 0); 9 Sep 2007 22:52:03 -0000 Received: from unknown (HELO phlook.local) (fgp@[10.105.0.26]) (envelope-sender ) by master.phlo.org (qmail-ldap-1.03) with SMTP for ; 9 Sep 2007 22:52:02 -0000 Message-ID: <46E47914.8000504@phlo.org> Date: Mon, 10 Sep 2007 00:52:04 +0200 From: "Florian G. Pflug" User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: Tom Lane CC: pgsql-patches@postgresql.org Subject: Re: WIP patch for latestCompletedXid method of computing snapshot xmax References: <3018.1189214811@sss.pgh.pa.us> <46E33D9A.9000009@phlo.org> <10093.1189305965@sss.pgh.pa.us> <46E38FB9.1030406@phlo.org> <18533.1189351373@sss.pgh.pa.us> In-Reply-To: <18533.1189351373@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/141 X-Sequence-Number: 3683 Tom Lane wrote: > "Florian G. Pflug" 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