Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fVULt-0000MG-R5 for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Jun 2018 04:04:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fVULs-0004dG-9A for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Jun 2018 04:04:12 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fVULr-0004d6-SR for pgsql-hackers@lists.postgresql.org; Wed, 20 Jun 2018 04:04:12 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fVULn-0004vb-IL for pgsql-hackers@postgresql.org; Wed, 20 Jun 2018 04:04:10 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id C1CC421C1D10; Wed, 20 Jun 2018 07:04:04 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.0.12] (unknown [62.148.227.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 59DB121C1D0C; Wed, 20 Jun 2018 07:04:04 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1529467444; bh=aeSMV5MJI9ulWDhUpdGkSfTli7gTaHaXOETfziJNTP4=; h=Subject:To:References:Cc:From:Date:In-Reply-To; b=ZUr8z4fydguzRcj+RqY+cveKcY8oyr9xM/IEsCvEFCBXDlvT537fitCuiEgxaaqco Uhr7swF9wdbHIgPQGXK12Suqcsc5LLKiDlAKUIJW8sP6l/ykYGmH1alF/QnEepNaVE b7XWT8gqkhQHOvlViC160ua6T4XlxyodaIXGkAg0= Subject: Re: [WIP] [B-Tree] Retail IndexTuple deletion To: Peter Geoghegan References: <425db134-8bba-005c-b59d-56e50de3b41e@postgrespro.ru> Cc: pgsql-hackers From: "Andrey V. Lepikhov" Message-ID: <0b74aa3e-3d76-397b-d14d-a4a24c3dfb1d@postgrespro.ru> Date: Wed, 20 Jun 2018 09:04:02 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 19.06.2018 04:05, Peter Geoghegan wrote: > On Mon, Jun 18, 2018 at 2:54 PM, Peter Geoghegan wrote: >> On Sun, Jun 17, 2018 at 9:39 PM, Andrey V. Lepikhov >> wrote: >>> Patch '0001-retail-indextuple-deletion' introduce new function >>> amtargetdelete() in access method interface. Patch >>> '0002-quick-vacuum-strategy' implements this function for an alternative >>> strategy of lazy index vacuum, called 'Quick Vacuum'. >> >> My compiler shows the following warnings: > > Some real feedback: > > What we probably want to end up with here is new lazyvacuum.c code > that does processing for one heap page (and associated indexes) that > is really just a "partial" lazy vacuum. Though it won't do things like > advance relfrozenxid, it will do pruning for the heap page, index > tuple killing, and finally heap tuple killing. It will do all of these > things reliably, just like traditional lazy vacuum. This will be what > your background worker eventually uses. > It is final goal of the patch. > I doubt that you can use routines like index_beginscan() within > bttargetdelete() at all. I think that you need something closer to > _bt_doinsert() or _bt_pagedel(), that manages its own scan (your code > should probably live in nbtpage.c). It does not make sense to teach > external, generic routines like index_beginscan() about heap TID being > an implicit final index attribute, which is one reason for this (I'm > assuming that this patch relies on my own patch). Another reason is > that you need to hold an exclusive buffer lock at the point that you > identify the tuple to be killed, until the point that you actually > kill it. You don't do that now. > > IOW, the approach you've taken in bttargetdelete() isn't quite correct > because you imagine that it's okay to occasionally "lose" the index > tuple that you originally found, and just move on. That needs to be > 100% reliable, or else we'll end up with index tuples that point to > the wrong heap tuples in rare cases with concurrent insertions. As I > said, we want a "partial" lazy vacuum here, which must mean that it's > reliable. Note that _bt_pagedel() actually calls _bt_search() when it > deletes a page. Your patch will not be the first patch that makes > nbtree vacuuming do an index scan. You should be managing your own > insertion scan key, much like _bt_pagedel() does. If you use my patch, > _bt_search() can be taught to look for a specific heap TID. > Agree with this notes. Corrections will made in the next version of the patch. > Finally, doing things this way would let you delete multiple > duplicates in one shot, as I described in an earlier e-mail. Only a > single descent of the tree is needed to delete quite a few index > tuples, provided that they all happen to be logical duplicates. Again, > your background worker will take advantage of this. > It is very interesting idea. According to this, I plan to change bttargetdelete() interface as follows: IndexTargetDeleteStats* amtargetdelete(IndexTargetDeleteInfo *info, IndexTargetDeleteStats *stats, Datum *values, bool *isnull); where structure IndexTargetDeleteInfo contains a TID list of dead heap tuples. All index entries, corresponding to this list, may be deleted (or only some of it) by one call of amtargetdelete() function with single descent of the tree. > This code does not follow the Postgres style: > >> - else >> + } >> + else { >> + if (rootoffnum != latestdead) >> + heap_prune_record_unused(prstate, latestdead); >> heap_prune_record_redirect(prstate, rootoffnum, chainitems[i]); >> + } >> } > > Please be more careful about that. I find it very distracting. > Done -- Andrey Lepikhov Postgres Professional: https://postgrespro.com The Russian Postgres Company