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.96) (envelope-from ) id 1vWw8k-00DJry-0y for pgsql-hackers@arkaria.postgresql.org; Sat, 20 Dec 2025 12:32:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vWw8j-00ARlY-0U for pgsql-hackers@arkaria.postgresql.org; Sat, 20 Dec 2025 12:32:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vWw8i-00ARlP-2L for pgsql-hackers@lists.postgresql.org; Sat, 20 Dec 2025 12:32:53 +0000 Received: from mail-qv1-xf35.google.com ([2607:f8b0:4864:20::f35]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vWw8h-001fGI-1a for pgsql-hackers@lists.postgresql.org; Sat, 20 Dec 2025 12:32:52 +0000 Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-88a22eb38edso16863916d6.2 for ; Sat, 20 Dec 2025 04:32:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766233970; x=1766838770; 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=XdHdFNwJKW5TiZqg2TZaj3XOy1R2nfrxMXYMkhwUfZk=; b=XjsZ7UtB9rp8z5eFdIqvmS8VompA0Fdx/ItZzYbUm/YSgvYNpPGkObIF73ys3ymt7c ieF3XAGQYjeDbObpzziT2/gBafekxpIdfnNT61XfMsWoXS80RWyYQpY1AViwC2l1vO5T noKe6xYIAJ7WjJjeTlXITHGGov5S/8tgUB2BUm70ckeYmd/jQl7U9Y1teM++SZG+G+GG ZXKh+qtkVugHm6Bhcyw9mQmCiKNvghbODVfj9PEiHMaMM+ymOF6oZRUu2kis+8k/wHPW Ws5a4HBhv6AcLIoqReJSY73IlC4X3XbCCZiDv7y6j6K5grTRi+EhC+oVzJdIpiecoo0b X0aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766233970; x=1766838770; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=XdHdFNwJKW5TiZqg2TZaj3XOy1R2nfrxMXYMkhwUfZk=; b=qBn1NoM/HtnA6WpCpLE89ATBkYGhMpoCWy8ETqspS8+/ecuiM6dolXAd2u0Rn84IUY WhxoHYqfMp3zGuih3Cm6A9KnJuACLYnjjVzEF4VVkijgniDZtDWsPC3dJIsQHFTB+BnM XjOxFPUBxsajuQV6lmNDXaJAT+5uy5KI1zQWXgzEvwwK40zd/w7nG4MfuCq8H5jui1GA Cu9dbI6LiTb6L0xCtcRXWw41PFjo+S05lqBG36mY7yimdVDlXUjk8OVxiPlbDA8ZOpUV pgrIWF1U1FUjQRmOAb2WFwT+V7MIACXBhcMEdNIsm2HDgBZ/ShGH9OYkq048p5QFezXn CD8g== X-Forwarded-Encrypted: i=1; AJvYcCUhxfbp1lUi3RmpP39h/iQHOtaXpzrbULz3LFA/TtFfz7HvImqip1Q9WLTwjMhqWrGfCcGQOplbBxKrs1lt@lists.postgresql.org X-Gm-Message-State: AOJu0Yw+LQOJngcZMEF3fc0L9RB9IZg4Okl8EEv7gziiKogo4dz1I6O/ /JkydvUqzUdgJwu859WeBY83sTLJ9jV1ykuh3YCf1O0eFg4B8TgG7z0qvrQH2ZOSmpS9SbTBddT MlyGP8IOHgueK1WkDf4Q4o7YI0NG5r3U= X-Gm-Gg: AY/fxX7bNyuQMx0lVTMfVE6HKa0Xk3rY5rL7VTap1K0PwBq7uSKa3HlTO1VqMIbcF8y mSh/n+PYN0RrFadoUxxLsc8XBg3Ze1VpqOI+CGVfnWmMucmYuvxgC+AnN0ldlhQCMHVdJ9BNQDk hXUAMFZM9Au6uCF6qy/CtzMvwUo6Pz9NFBfft3/YuKHUeo9i5vDcnkTpxCusWo39o2/8qA+tTpz 3WerEjYRA5uYUfPFKFJmiWVDPYQ2mdbD1b4s9V60lOC6c9itiah6qvkM5+vrHVDEGCz70Q4aWnG cZR/sQZq X-Google-Smtp-Source: AGHT+IE/gZ3+WPi5ujwCtUKNL/K1nSvQkAfcBY1+CsiyY7/cTxGScCJm3S++Zn7ohffNBS7WgUNGXz/KgNpFosxIh/U= X-Received: by 2002:a05:6214:3386:b0:70f:5a6d:a253 with SMTP id 6a1803df08f44-88d83d66e20mr93531136d6.49.1766233970162; Sat, 20 Dec 2025 04:32:50 -0800 (PST) MIME-Version: 1.0 References: <2wk7jo4m4qwh5sn33pfgerdjfujebbccsmmlownybddbh6nawl@mdyyqpqzxjek> In-Reply-To: From: Kirill Reshke Date: Sat, 20 Dec 2025 17:32:38 +0500 X-Gm-Features: AQt7F2r9Gb1SM1YzAuW-b5AM0M7aURiZT5YTcRRl1MxkMtMyToddUkbHBjpkoBU Message-ID: Subject: Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access) To: Melanie Plageman Cc: Xuneng Zhou , Andres Freund , Robert Haas , Andrey Borodin , PostgreSQL Hackers , Heikki Linnakangas , Chao Li 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 Sat, 20 Dec 2025 at 02:10, Melanie Plageman wrote: > > Attached v29 addresses some feedback and also corrects a small error > with the assertion I had added in the previous version's 0009. > > On Thu, Dec 18, 2025 at 10:38=E2=80=AFPM Xuneng Zhou wrote: > > > > I=E2=80=99ve done a basic review of patches 1 and 2. Here are some comm= ents > > which may be somewhat immature, as this is a fairly large change set > > and I=E2=80=99m new to some parts of the code. > > > > 1) Potential stale old_vmbits after VM repair n v2 > > Good catch! I've fixed this in attached v29. > > > 2) Add Assert(BufferIsDirty(buf)) > > > > Since the patch's core claim is "buffer must be dirty before WAL > > registration", an assertion encodes this invariant. Should we add: > > > > Assert(BufferIsValid(buf)); > > Assert(BufferIsDirty(buf)); > > > > right before the visibilitymap_set() call? > > There are already assertions that will trip in various places -- most > importantly in XLogRegisterBuffer(), which is the one that inspired > this refactor. > > > The comment at lines: > > > "The only scenario where it is not already dirty is if the VM was rem= oved=E2=80=A6" > > > > This phrasing could become misleading after future refactors. Can we > > make it more direct like: > > > > > "We must mark the heap buffer dirty before calling visibilitymap_set(= ), because it may WAL-log the buffer and XLogRegisterBuffer() requires it." > > I see your point about future refactors missing updating comments like > this. But, I don't think we are going to refactor the code such that > we can have PD_ALL_VISIBLE set without the VM bits set more often. > Also, it is common practice in Postgres to describe very specific edge > cases or odd scenarios in order to explain code that may seem > confusing without the comment. It does risk that comment later > becoming stale, but it is better that future developers understand why > the code is there. > > That being said, I take your point that the comment is confusing. I > have updated it in a different way. > > > > "Even if PD_ALL_VISIBLE is already set, we don't need to worry about = unnecessarily dirtying the heap buffer, as it must be marked dirty before a= dding it to the WAL chain. The only scenario where it is not already dirty = is if the VM was removed..." > > > > In this test we now call MarkBufferDirty() on the heap page even when > > only setting the VM, so the comments claiming =E2=80=9Cdoes not need to= modify > > the heap buffer=E2=80=9D/=E2=80=9Cno heap page modification=E2=80=9D mi= ght be misleading. It > > might be better to say the test doesn=E2=80=99t need to modify heap > > tuples/page contents or doesn=E2=80=99t need to prune/freeze. > > The point I'm trying to make is that we have to dirty the buffer even > if we don't modify the page because of the XLOG sub-system > requirements. And, it may seem like a waste to do that if not > modifying the page, but the page will rarely be clean anyway. I've > tried to make this more clear in attached v29. > > - Melanie Hi! I checked v29-0009, about HeapTupleSatisfiesVacuumHorizon. Origins of this code track down to fdf9e21196a6 which was committed as part of [0], at which point there was no HeapTupleSatisfiesVacuumHorizon function. I guess this is the reason this optimization was not performed earlier. I also think this patch is correct, because we do similar things for HEAPTUPLE_DEAD & HEAPTUPLE_RECENTLY_DEAD, and HeapTupleSatisfiesVacuumHorizon is just a proxy to HeapTupleSatisfiesVacuumHorizon with only difference in DEAD VS RECENTLY_DEAD handling. Similar change could be done at heapam_scan_analyze_next_tuple ... case HEAPTUPLE_DEAD: case HEAPTUPLE_RECENTLY_DEAD: /* Count dead and recently-dead rows */ *deadrows +=3D 1; break; ... [0] https://www.postgresql.org/message-id/CABOikdP0meGuXPPWuYrP%3DvDvoqUdsh= F2xJAzZHWSKg03Rz_%2B9Q%40mail.gmail.com --=20 Best regards, Kirill Reshke