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 1fY1iN-0003gt-9D for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Jun 2018 04:05:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fY1iK-0005kr-Rp for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Jun 2018 04:05:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fY1iK-0005kj-Bg for pgsql-hackers@lists.postgresql.org; Wed, 27 Jun 2018 04:05:52 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fY1iC-0005qJ-Jh for pgsql-hackers@postgresql.org; Wed, 27 Jun 2018 04:05:51 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 1E9CF21C1CD0; Wed, 27 Jun 2018 07:05:43 +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.106] (unknown [5.79.139.6]) (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 BCFA921C1CBA; Wed, 27 Jun 2018 07:05:42 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1530072342; bh=WImdj/TA/NYgrmnYp0x3SRz8GMGJt4FspwovY+02M8Q=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=V9x1ZeEUSlA/dGuXdIjurT3Z4lA1lHyO2Spm6q3fiMqvgGFRLsFO8ArGetOOrgh6x NGLj/vyYwX38cwnKEC7rhqMdlUf7FJVbGlKKbSRTPfpg0ac3h0ga3Ip+qqgM/ZclaL /8cXQuLPkZrixlJeqYI6qQoDw2bosP4RHxFGR54E= Subject: Re: [WIP] [B-Tree] Retail IndexTuple deletion To: Masahiko Sawada Cc: Peter Geoghegan , PostgreSQL Hackers References: <425db134-8bba-005c-b59d-56e50de3b41e@postgrespro.ru> <5affa50e-72a9-aef5-d71f-f5f551e01aaf@postgrespro.ru> From: "Andrey V. Lepikhov" Message-ID: <40c94500-ee09-2d14-169b-c6a7b5d46f9b@postgrespro.ru> Date: Wed, 27 Jun 2018 09:05:41 +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 26.06.2018 15:31, Masahiko Sawada wrote: > On Fri, Jun 22, 2018 at 8:24 PM, Andrey V. Lepikhov > wrote: >> Hi, >> According to your feedback, i develop second version of the patch. >> In this version: >> 1. High-level functions index_beginscan(), index_rescan() not used. Tree >> descent made by _bt_search(). _bt_binsrch() used for positioning on the >> page. >> 2. TID list introduced in amtargetdelete() interface. Now only one tree >> descent needed for deletion all tid's from the list with equal scan key >> value - logical duplicates deletion problem. >> 3. Only one WAL record for index tuple deletion per leaf page per >> amtargetdelete() call. >> 4. VACUUM can sort TID list preliminary for more quick search of duplicates. >> >> Background worker will come later. >> >> > > Thank you for updating patches! Here is some comments for the latest patch. > > +static void > +quick_vacuum_index(Relation irel, Relation hrel, > + IndexBulkDeleteResult **overall_stats, > + LVRelStats *vacrelstats) > +{ > (snip) > + /* > + * Collect statistical info > + */ > + lazy_cleanup_index(irel, *overall_stats, vacrelstats); > +} > > I think that we should not call lazy_cleanup_index at the end of > quick_vacuum_index because we call it multiple times during a lazy > vacuum and index statistics can be changed during vacuum. We already > call lazy_cleanup_index at the end of lazy_scan_heap. > Ok > bttargetdelete doesn't delete btree pages even if pages become empty. > I think we should do that. Otherwise empty page never be recycled. But > please note that if we delete btree pages during bttargetdelete, > recyclable pages might not be recycled. That is, if we choose the > target deletion method every time then the deleted-but-not-recycled > pages could never be touched, unless reaching > vacuum_cleanup_index_scale_factor. So I think we need to either run > bulk-deletion method or do cleanup index before btpo.xact wraparound. > > + ivinfo.indexRelation = irel; > + ivinfo.heapRelation = hrel; > + qsort((void *)vacrelstats->dead_tuples, > vacrelstats->num_dead_tuples, sizeof(ItemPointerData), > tid_comparator); > Ok. I think caller of bttargetdelete() must decide when to make index cleanup. > I think the sorting vacrelstats->dead_tuples is not necessary because > garbage TIDs are stored in a sorted order. > Sorting was introduced because I keep in mind background worker and more flexible cleaning strategies, not only full tuple-by-tuple relation and block scan. Caller of bttargetdelete() can set info->isSorted to prevent sorting operation. > Regards, > > -- > Masahiko Sawada > NIPPON TELEGRAPH AND TELEPHONE CORPORATION > NTT Open Source Software Center > -- Andrey Lepikhov Postgres Professional: https://postgrespro.com The Russian Postgres Company