Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id EE49864FE6F for ; Tue, 28 Oct 2008 10:50:00 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 57600-01 for ; Tue, 28 Oct 2008 10:49:53 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ey-out-2122.google.com (ey-out-2122.google.com [74.125.78.27]) by postgresql.org (Postfix) with ESMTP id F39B964FD6E for ; Tue, 28 Oct 2008 10:49:52 -0300 (ADT) Received: by ey-out-2122.google.com with SMTP id 6so1130361eyi.61 for ; Tue, 28 Oct 2008 06:49:51 -0700 (PDT) Received: by 10.210.119.5 with SMTP id r5mr8368836ebc.89.1225201791062; Tue, 28 Oct 2008 06:49:51 -0700 (PDT) Received: from ?88.195.116.231? (dsl-hkibrasgw2-ff74c300-231.dhcp.inet.fi [88.195.116.231]) by mx.google.com with ESMTPS id d23sm8556427nfh.11.2008.10.28.06.49.49 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 28 Oct 2008 06:49:50 -0700 (PDT) Message-ID: <4907187B.7060103@enterprisedb.com> Date: Tue, 28 Oct 2008 15:49:47 +0200 Organization: EnterpriseDB User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: Tom Lane CC: PostgreSQL-development Subject: Re: Visibility map, partial vacuums References: <4905AE17.7090305@enterprisedb.com> <26727.1225150278@sss.pgh.pa.us> In-Reply-To: <26727.1225150278@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit From: Heikki Linnakangas X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200810/1404 X-Sequence-Number: 126421 Tom Lane wrote: > Heikki Linnakangas writes: >> To modify a page: >> If PD_ALL_VISIBLE flag is set, the bit in the visibility map is cleared >> first. The heap page is kept pinned, but not locked, while the >> visibility map is updated. We want to avoid holding a lock across I/O, >> even though the visibility map is likely to stay in cache. After the >> visibility map has been updated, the page is exclusively locked and >> modified as usual, and PD_ALL_VISIBLE flag is cleared before releasing >> the lock. > > So after having determined that you will modify a page, you release the > ex lock on the buffer and then try to regain it later? Seems like a > really bad idea from here. What if it's no longer possible to do the > modification you intended? In case of insert/update, you have to find a new target page. I put the logic in RelationGetBufferForTuple(). In case of delete and update (old page), the flag is checked and bit cleared just after pinning the buffer, before doing anything else. (I note that that's not actually what the patch is doing for heap_update, will fix..) If we give up on the strict requirement that the bit in the visibility map has to be cleared if the PD_ALL_VISIBLE flag on the page is not set, then we could just update the visibility map after releasing the locks on the heap pages. I think I'll do that for now, for simplicity. >> To set the PD_ALL_VISIBLE flag, you must hold an exclusive lock on the >> page, while you observe that all tuples on the page are visible to everyone. > > That doesn't sound too good from a concurrency standpoint... Well, no, but it's only done in VACUUM. And pruning. I implemented it as a new loop that call HeapTupleSatisfiesVacuum on each tuple, and checking that xmin is old enough for live tuples, but come to think of it, we're already calling HeapTupleSatisfiesVacuum for every tuple on the page during VACUUM, so it should be possible to piggyback on that by restructuring the code. >> That's how the patch works right now. However, there's a small >> performance problem with the current approach: setting the >> PD_ALL_VISIBLE flag must be WAL-logged. Otherwise, this could happen: > > I'm more concerned about *clearing* the bit being WAL-logged. That's > necessary for correctness. Yes, clearing the PD_ALL_VISIBLE flag always needs to be WAL-logged. There's a new boolean field in xl_heap_insert/update/delete records indicating if the operation cleared the flag. On replay, if the flag was cleared, the bit in the visibility map is also cleared. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com