Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kzNII-0000wf-BH for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Jan 2021 17:17:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kzNIH-0007rB-9z for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Jan 2021 17:17:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kzNIH-0007r4-0n for pgsql-hackers@lists.postgresql.org; Tue, 12 Jan 2021 17:17:21 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kzNIE-0005dD-JH for pgsql-hackers@lists.postgresql.org; Tue, 12 Jan 2021 17:17:20 +0000 Received: from [192.168.1.70] (ppp91-79-10-53.pppoe.mtu-net.ru [91.79.10.53]) (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 55EF021C2F49; Tue, 12 Jan 2021 20:17:17 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1610471837; bh=ZzC7ih3yoKzd8+7/fgqA7tleKqCtjxEVwK9wHPxKPO0=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=flGL//k77rBQWexFrFcuhZTrlSnhvNl4Js2LKizMR2FDjd1r5B+7Ohgd9bZfy/fES R7y9zUod0odSi2BkW7fpLUODgOIaHiZ5ML+BZ03rjPKxSiHA1+m01H3y0IsibJtHek 5bPu3ougXOS2hSuUJyIaNYIpoKnkXs4XNX+wNb2I= Subject: Re: COPY FREEZE and setting PD_ALL_VISIBLE/visibility map bits To: Tomas Vondra , Tomas Vondra Cc: Tatsuo Ishii , lubennikovaav@gmail.com, pgsql-hackers@lists.postgresql.org, pavan.deolasee@gmail.com, ibrar.ahmad@gmail.com References: <160382617166.1204.475752573208579406.pgcf@coridan.postgresql.org> <20201028.144653.966121790856478893.t-ishii@sraoss.co.jp> <20201030004252.d63rwclys4bniluu@development> <1d2e0f4a-6ab8-10f1-c177-af97475df001@postgrespro.ru> <20201102144453.tumlk7qhw3gzn2dk@development> <7e6a006f-c59a-93fc-3ddf-f9c661319bc8@2ndquadrant.com> <75f3760f-1077-07c1-aea4-975d5c127d6d@postgrespro.ru> From: Anastasia Lubennikova Message-ID: <93b767d6-4cde-7326-8de4-d71d81817c16@postgrespro.ru> Date: Tue, 12 Jan 2021 20:17:17 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12.01.2021 00:51, Tomas Vondra wrote: > > > On 1/11/21 10:00 PM, Anastasia Lubennikova wrote: >> On 11.01.2021 01:35, Tomas Vondra wrote: >>> Hi, >>> >>> I started looking at this patch again, hoping to get it committed in >>> this CF, but I think there's a regression in handling TOAST tables >>> (compared to the v3 patch submitted by Pavan in February 2019). >>> >>> The test I'm running a very simple test (see test.sql): >>> >>> 1) start a transaction >>> 2) create a table with a text column >>> 3) copy freeze data into it >>> 4) use pg_visibility to see how many blocks are all_visible both in the >>>    main table and it's TOAST table >>> >>> For v3 patch (applied on top of 278584b526 and >>> s/hi_options/ti_options) I get this: >>> >>>            pages           NOT all_visible >>>   ------------------------------------------ >>>   main       637                         0 >>>   toast    50001                         3 >>> >>> There was some discussion about relcache invalidations causing a >>> couple TOAST pages not be marked as all_visible, etc. >>> >>> However, for this patch on master I get this >>> >>>            pages           NOT all_visible >>>   ------------------------------------------ >>>   main       637                         0 >>>   toast    50001                     50001 >>> >>> So no pages in TOAST are marked as all_visible. I haven't >>> investigated what's causing this, but IMO that needs fixing to make >>> ths patch RFC. >>> >>> Attached is the test script I'm using, and a v5 of the patch - >>> rebased on current master, with some minor tweaks to comments etc. >>> >> >> Thank you for attaching the test script. I reproduced the problem. >> This regression occurs because TOAST internally uses heap_insert(). >> You have asked upthread about adding this optimization to heap_insert(). >> >> I wrote a quick fix, see the attached patch 0002. The TOAST test >> passes now, but I haven't tested performance or any other use-cases yet. >> I'm going to test it properly in a couple of days and share results. >> > > Thanks. I think it's important to make this work for TOAST tables - it > often stores most of the data, and it was working in v3 of the patch. > I haven't looked into the details, but if it's really just due to > TOAST using heap_insert, I'd say it just confirms the importance of > tweaking heap_insert too. I've tested performance. All tests were run on my laptop, latest master with and without patches, all default settings, except disabled autovacuum and installed pg_stat_statements extension. The VACUUM is significantly faster with the patch, as it only checks visibility map. COPY speed fluctuates a lot between tests, but I didn't notice any trend. I would expect minor slowdown with the patch, as we need to handle visibility map pages during COPY FREEZE. But in some runs, patched version was faster than current master, so the impact of the patch is insignificant. I run 3 different tests: 1) Regular table (final size 5972 MB) patched           |   master COPY FREEZE data 3 times: 33384,544 ms   31135,037 ms 31666,226 ms   31158,294 ms 32802,783 ms   33599,234 ms VACUUM 54,185 ms         48445,584 ms 2) Table with TOAST (final size 1207 MB where 1172 MB is in toast table) patched             |   master COPY FREEZE data 3 times: 368166,743 ms    383231,077 ms 398695,018 ms    454572,630 ms 410174,682 ms    567847,288 ms VACUUM 43,159 ms            6648,302 ms 3) Table with a trivial BEFORE INSERT trigger (final size 5972 MB) patched             |   master COPY FREEZE data 3 times: 73544,225 ms      64967,802 ms 90960,584 ms      71826,362 ms 81356,025 ms      80023,041 ms VACUUM 49,626 ms            40100,097 ms I took another look at the yesterday's patch and it looks fine to me. So now I am waiting for your review. -- Anastasia Lubennikova Postgres Professional: http://www.postgrespro.com The Russian Postgres Company