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 1nLa08-0004BN-Rc for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Feb 2022 00:22:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nLa07-0007Tf-LJ for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Feb 2022 00:22:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nLa07-0007TW-7R for pgsql-hackers@lists.postgresql.org; Sun, 20 Feb 2022 00:22:55 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nLa04-0003i8-4D for pgsql-hackers@lists.postgresql.org; Sun, 20 Feb 2022 00:22:54 +0000 Received: by mail-ej1-x634.google.com with SMTP id a23so23774323eju.3 for ; Sat, 19 Feb 2022 16:22:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bowt-ie.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pJ+b7E7ZwpCQITpJhq75JhVhtVIB9OvrK9BMBfSho78=; b=XL/1c/8iYYwnCNuOkNRpY5YgWvYee3dGG4HQ7LTNVjSnKtWARfhsvXI87v36VYlNke n3YEf4VWuKTAgUDJTBz3b8QpoJ9druIcxEPlJMejoQEw2wmJiZn9VugsbQD//Xw5TGXJ Pr1xKkA3eL5FiqrQJ4ZNXFWsF96YOZwFv/HVkcuBOL6B98NzRq91ClgL5EEgMm3apnqI FLfWM9+ZhSi8r4AmxPyUt5tndvUWELXlg/Z+WnwpSPG728mD5K6mqyTZBEfwU03g6AkR GfqUIVLOBbqNI+7k2Wc+5aDWyWzsVrKbUIdAqJGUnmq7OQwklmeRSMROpw5h74yg56/e +JWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pJ+b7E7ZwpCQITpJhq75JhVhtVIB9OvrK9BMBfSho78=; b=xKCUtaxflDRTZlstXU7KThW7GWxiaFK5+2Sscxgpi6PRZtu5LgtflP2nhLTT0tnjkK +c+/2+eXOTGKQ/H3k9/zbJXPH9npVM7IXVCmTEI+fNRoAGHsM4XsqbwgsaJbR/DTve7y mXwZ9AIjFmUxlkMhiZ4TTSw5A2VtkWggl6L/9tZP1eKKWDJ3/DpcCcS76G+ikGndNGRR pRHJyheRdsL9IcVLtPwJJqgBlq4q5nBOLLp0VY6AOpDzPhcaBr+v/haCVo2t27y6coRb pFeDnI/0HNX1cj8ZNVvQOBZKP0GoBxJE6Oypr4S5m0VNcDXTIM95b0OrQo+mH4NaUtQY LH4g== X-Gm-Message-State: AOAM533VRYeVdlbio+Kho44494Qtv17Asp0uvLM2TfBrPEajw4tp156v +I645HNNROudBO6V+1eOUj8o94s7ln49KcEPRznk0Q== X-Google-Smtp-Source: ABdhPJxK/z+caelRKegk5OE5IQshyFLKsBwY+AK3m63uaL1j93PED7qrX+7/tblHulCG7DwrOSNp2WzGkwlVKf71h4Y= X-Received: by 2002:a17:906:40c9:b0:6cf:1fb3:aca with SMTP id a9-20020a17090640c900b006cf1fb30acamr10953384ejk.101.1645316570353; Sat, 19 Feb 2022 16:22:50 -0800 (PST) MIME-Version: 1.0 References: <20220218221117.ijozsjwaxa6fy5u6@alap3.anarazel.de> In-Reply-To: From: Peter Geoghegan Date: Sat, 19 Feb 2022 16:22:23 -0800 Message-ID: Subject: Re: Removing more vacuumlazy.c special cases, relfrozenxid optimizations To: Andres Freund Cc: Robert Haas , Masahiko Sawada , PostgreSQL Hackers Content-Type: multipart/mixed; boundary="000000000000b883ee05d8681db8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b883ee05d8681db8 Content-Type: text/plain; charset="UTF-8" On Sat, Feb 19, 2022 at 3:08 PM Peter Geoghegan wrote: > It's quite possible that this is nothing more than a bug in my > adversarial gizmo patch -- since I don't think that > ConditionalLockBufferForCleanup() can ever fail with a temp buffer > (though even that's not completely clear right now). Even if the > behavior that I saw does not indicate a bug on HEAD, it still seems > informative. This very much looks like a bug in pg_surgery itself now -- attached is a draft fix. The temp table thing was a red herring. I found I could get exactly the same kind of failure when htab2 was a permanent table (which was how it originally appeared, before commit 0811f766fd made it into a temp table due to test flappiness issues). The relevant "vacuum freeze htab2" happens at a point after the test has already deliberately corrupted one of its tuples using heap_force_kill(). It's not that we aren't careful enough about the corruption at some point in vacuumlazy.c, which was my second theory. But I quickly discarded that idea, and came up with a third theory: the relevant heap_surgery.c path does the relevant ItemIdSetDead() to kill items, without also defragmenting the page to remove the tuples with storage, which is wrong. This meant that we depended on pruning happening (in this case during VACUUM) and defragmenting the page in passing. But there is no reason to not defragment the page within pg_surgery (at least no obvious reason), since we have a cleanup lock anyway. Theoretically you could blame this on lazy_scan_noprune instead, since it thinks it can collect LP_DEAD items while assuming that they have no storage, but that doesn't make much sense to me. There has never been any way of setting a heap item to LP_DEAD without also defragmenting the page. Since that's exactly what it means to prune a heap page. (Actually, the same used to be true about heap vacuuming, which worked more like heap pruning before Postgres 14, but that doesn't seem important.) -- Peter Geoghegan --000000000000b883ee05d8681db8 Content-Type: text/plain; charset="US-ASCII"; name="0002-Fix-for-pg_surgery-s-heap_force_kill-function.txt" Content-Disposition: attachment; filename="0002-Fix-for-pg_surgery-s-heap_force_kill-function.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kzuiqtvi0 RnJvbSA4MWYwMWNhNjIzYjExNTY0N2VlNzh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