Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uw3z5-005a1x-63 for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Sep 2025 19:26:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uw3z4-00E7bH-1D for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Sep 2025 19:26:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uw3z3-00E7b9-Mo for pgsql-hackers@lists.postgresql.org; Tue, 09 Sep 2025 19:26:30 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uw3z0-001ZkI-0n for pgsql-hackers@lists.postgresql.org; Tue, 09 Sep 2025 19:26:29 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-b04ba3de760so434883066b.0 for ; Tue, 09 Sep 2025 12:26:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757445981; x=1758050781; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=LbVrTJvLyupKXsai3Z4zByNFXN2b5Q8ivC1AZidM6/Y=; b=VgTbzZZCmVxdm2rBGS4uft15wzNjmz5TMwB7swfYMFfwp9fNl+86ioYu9gshE+cpjv qLvz3xODWpv5ua22ayN5+Zr1/T1jWduAvbsIMAQU0DsgsJoSBwRr6aKEKZcv8loKLE6b IZUeBi9SS+lYizSgBy8hjq1J68sx1Gj304m/Z04L5T+Lwya0/9AJMqS4gHi7SvAf95bf MFU03MJNuQHkX65wNjSewHecofgOqCdbow8OoQ+w7iMUY2hzEt8PFn/7b/51jWgXl8oL viewDxlGad5TGv+3zDzZsLasaSS3ApY/7fY/YFIDxKE9mq0psNTIiwtHmSix66QKeEes p6VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757445981; x=1758050781; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LbVrTJvLyupKXsai3Z4zByNFXN2b5Q8ivC1AZidM6/Y=; b=cYEoa1r+vRs1cH1mt+yZ1vbwsJeQBvqtYJ+p2oY9EGvmJ/F+HCchGy4gCJygqbPqmf Aczaxy9sjvqBxDkJmQji6/35zguEl1kHxbMlJVPfV+e79uGPwQ12mac64sUlYhmxL8/o HPRpiMXa5tAjvESZUZ3J+pCVLn0qXNFh+NVCrMjQ8+yMz1jeibfRsPDLnOAid/xGM3u8 7ADX3WSryw38ImTSSTlTlYMgBpPuvm8oPf+kscWowi3oks+8/U7XDlEZRQ6z1r+9qLp5 wOPyyLWW2T4wiJNnCljKB4iM8AO69yDJfFpqPjF/PHa7vgkwkbyhBldVY3aB/ANrg+1K fQGw== X-Forwarded-Encrypted: i=1; AJvYcCW2hNWhKHE/usNhoLwq4T2zIjrPJp9hZC4JDCogNaCPftBf8xmkzmMnXWl/xo19lt24+riPXPgVm/ZdQMks@lists.postgresql.org X-Gm-Message-State: AOJu0Yyh6B9WUG+khhpnpUsGDJVIjs5LbAF02sMa+fLwSLO7YQF2m4xE 98hCDQINEmJN/fMcvr/AEXiB7+BODlZwGptnGoNoIfxaz82op/qHf034nZcodomdu325+0qDl8d NjY8VrJB+FzB7ndQBJvkJaa3EXtx5Y2E= X-Gm-Gg: ASbGncu4SEKJ3047OzdPLqz5QNRWiSK3JAWs5TMKAdmPbUa1Q4T0Rid1WkEZ1qj5Bx6 VC4vB020moEVQtSnl1LNQptuNh0FyW+w0rIAXEEuohsc4zMCS9oUg42VG0liFI8LmVBzFcc3nMD xkN2quwbwN8ZarNGu9QBzapl5uvIh8vLQWWWFyy4q+nxFn65xPbDsNrwEflURd4c9wshN6q8zDZ YxbD2Q= X-Google-Smtp-Source: AGHT+IFx2sotTZpgZEbiT/aGR76ICwDFhsV27bDqmhJj0OCjJdfi1iOuUDiARCjhYJt3WzvksXTB/Y4EkSe3foNZrNo= X-Received: by 2002:a17:907:3f9b:b0:afe:ae6c:411c with SMTP id a640c23a62f3a-b04b17353e5mr1086726866b.64.1757445981041; Tue, 09 Sep 2025 12:26:21 -0700 (PDT) MIME-Version: 1.0 References: <87DD95AA-274F-4F4F-BAD9-7738E5B1F905@yandex-team.ru> In-Reply-To: From: Robert Haas Date: Tue, 9 Sep 2025 15:26:08 -0400 X-Gm-Features: Ac12FXyCmbqkjGm9l2uhQ6DgMy6iUTXkGprIOnMY7iiEXQ7xns6-_j8h_bn_lmk Message-ID: Subject: Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access) To: Melanie Plageman Cc: Andres Freund , Kirill Reshke , Andrey Borodin , PostgreSQL Hackers , Heikki Linnakangas Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Sep 9, 2025 at 12:24=E2=80=AFPM Melanie Plageman wrote: > For heap_xlog_visible() the LSN interlock comment is easier to parse > because of an earlier comment before reading the heap page: > > /* > * Read the heap page, if it still exists. If the heap file has dropp= ed or > * truncated later in recovery, we don't need to update the page, but= we'd > * better still update the visibility map. > */ > > I've gone with the direct copy-paste of the LSN interlock paragraph in > attached v12. I think referring to the other comment is too confusing > in context here. However, I also added a line about what could cause > the LSN interlock -- but above it, so as to retain grep-ability of the > other comment. I think that reads a little strangely. I would consolidate: Note that the heap relation may have been dropped or truncated, leading us to skip updating the heap block due to the LSN interlock. However, even in that case, it's still safe to update the visibility map, etc. The rest of the comment is perhaps a tad more explicit than our usual practice, but that might be a good thing, because sometimes we're a little too terse about these critical details. I just realized that I don't like this: + /* + * If we're only adding already frozen rows to a previously empty + * page, mark it as all-frozen and update the visibility map. We're + * already holding a pin on the vmbuffer. + */ The thing is, we rarely position a block comment just before an "else if". There are probably instances, but it's not typical. That's why the existing comment contains two "if blah then blah" statements of which you deleted the second -- because it needed to cover both the "if" and the "else if". An alternative style is to move the comment down a nesting level and rephrase without the conditional, ie. "We're only adding frozen rows to a previously empty page, so mark it as all-frozen etc." But I don't know that I like doing that for one branch of the "if" and not the other. The rest of what's now 0001 looks OK to me now, although you might want to wait for a review from somebody more knowledgeable about this area. Some very quick comments on the next few patches -- far from a full review: 0002. Looks boring, probably unobjectionable provided the payoff patch is O= K. 0003. What you've done here with xl_heap_prune.flags is kind of horrifying. The problem is that, while you've added code explaining that VISIBILITYMAP_ALL_{VISIBLE,FROZEN} are honorary XLHP flags, nobody who isn't looking directly at that comment is going to understand the muddling of the two namespaces. I would suggest not doing this, even if it means defining redundant constants and writing technically-unnecessary code to translate between them. 0004. It is not clear to me why you need to get log_heap_prune_and_freeze to do the work here. Why can't log_newpage_buffer get the job done already? 0005. It looks a little curious that you delete the identify-corruption logic from the end of the if-nest and add it to the beginning. Ceteris paribus, you'd expect that to be worse, since corruption is a rare case. 0006. "to me marked" -> "to be marked". + * If the heap page is all-visible but the VM bit is not set, we don't + * need to dirty the heap page. However, if checksums are enabled, we + * do need to make sure that the heap page is dirtied before passing + * it to visibilitymap_set(), because it may be logged. */ - PageSetAllVisible(page); - MarkBufferDirty(buf); + if (!PageIsAllVisible(page) || XLogHintBitIsNeeded()) + { + PageSetAllVisible(page); + MarkBufferDirty(buf); + } I really hate this. Maybe you're going to argue that it's not the job of this patch to fix the awfulness here, but surely marking a buffer dirty in case some other function decides to WAL-log it is a ridiculous plan. --=20 Robert Haas EDB: http://www.enterprisedb.com