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 1kz564-0003z4-Ug for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Jan 2021 21:51:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kz563-0002nh-SH for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Jan 2021 21:51:31 +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 1kz563-0002na-II for pgsql-hackers@lists.postgresql.org; Mon, 11 Jan 2021 21:51:31 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kz560-0004cS-5s for pgsql-hackers@lists.postgresql.org; Mon, 11 Jan 2021 21:51:31 +0000 Received: by mail-ej1-x629.google.com with SMTP id w1so494181ejf.11 for ; Mon, 11 Jan 2021 13:51:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=pgf5vCKzZR/5X/Sg0uPOig6FzRJCn3Bk8dT40Njr/zc=; b=C4tFJ2qZ30YZNLx1DwacQ+tIvkZdCrJxCbIbylpKw5VQ38cqBPuqgywtLMjN0MRNEQ qLgfhz8Wp56w5oLr6LTWiWD/VOJULDlj26uPqt3EJrJjwyaQESQoJjuXSrRAdIgeB+Xt 3NVO4H7qo0ogVfiuTuYJ4vQfAXr1AXVGcivWOS5G4Gwciq+Ap+Sr+LAQAMEZRm2jP9dB AKtiJ+KC6y1YfVRd3n6eLbIL17sTdK28ud6iDvBiKdqsW14B6eH+6vqi0EAyCfNnF+AR RXOZAjTEJKKzYXl5Tmbt8RzhDRq/Y+GJrVaY+6ipbOu18PG35YmURENNYuQ06GTw3ovF 1Wmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=pgf5vCKzZR/5X/Sg0uPOig6FzRJCn3Bk8dT40Njr/zc=; b=mGARNhY6Ta3DwfGdnFoK3gVjNxuI1AocNVke3gpOkoEoJFzQygYzB4dujE5mcaA3mK JWIWd7mJOCz3Q0dZcFO114KKdFJT1JU4mElw4w+8N3D1iQs8n7tkr9TFoj/N5RBCic6H UMrsvEnK+5N/IQw8dE78GZN+2u3KVNJG1BxzTdHkEZSb3KCefxpjS4Ehka4/sgk+oKL4 Ug97Eo/fj0PCLx5Mcgd2HyvEwm5UEbYX/7LdrYYvTrdXR5yOG2UAwPaNl8XmLUiLvCeJ mrgnfv/Xlg3+PDJWrxmUzCLFavz28Okuw9FAQNaFdxok6Hk97fPNK2Yxrj1KVttuQmT6 qM3g== X-Gm-Message-State: AOAM53334RRrhquyKmITcyNUnPR3PkoiACqKoy2+YjBzsmcL6pRoSAJi lOlos4UsajpwEzvk7MV9GoBxihqIbBASOKIuqAj2qzMRURQMGpdYUQEvKyMpvKSBk3zyfxCnwQB HF25WJTtw2yjV3qNiCbTE5slWC30cV+XAuitBDD0uEgl1WOnR+QKQJk18oulvPcNVp0m3sQAWFp wsyLI7tyL66ngXMqWPDhrrelJWvK0tzUmLDdN/7T5qo6RNZkliG2zk X-Google-Smtp-Source: ABdhPJznIwtdm/IMtJJzCqUsSfoWumkaEOycaHOzeLf5dp/uKeN5CcG9KyfrLImYEPwcljyD2Qi8IA== X-Received: by 2002:a17:906:dfd5:: with SMTP id jt21mr966797ejc.519.1610401886476; Mon, 11 Jan 2021 13:51:26 -0800 (PST) Received: from [10.137.0.20] (ip-86-49-253-127.net.upcbroadband.cz. [86.49.253.127]) by smtp.gmail.com with ESMTPSA id k15sm349140ejc.79.2021.01.11.13.51.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Jan 2021 13:51:25 -0800 (PST) Subject: Re: COPY FREEZE and setting PD_ALL_VISIBLE/visibility map bits To: Anastasia Lubennikova , 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: Tomas Vondra Message-ID: Date: Mon, 11 Jan 2021 22:51:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <75f3760f-1077-07c1-aea4-975d5c127d6d@postgrespro.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. > With this change a lot of new code is repeated in heap_insert() and > heap_multi_insert(). I think it's fine, because these functions already > have a lot in common. > Understood. IMHO a bit of redundancy is not a big issue, but I haven't looked at the code yet. Let's get it working first, then we can decide if some refactoring is appropriate. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company