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 1vWRKE-001CNm-2C for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Dec 2025 03:38:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vWRKD-005lLQ-0o for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Dec 2025 03:38:42 +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 1vWRKC-005lLI-2f for pgsql-hackers@lists.postgresql.org; Fri, 19 Dec 2025 03:38:41 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vWRKB-001R8N-2X for pgsql-hackers@lists.postgresql.org; Fri, 19 Dec 2025 03:38:40 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-b76b5afdf04so202003566b.1 for ; Thu, 18 Dec 2025 19:38:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766115518; x=1766720318; 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=qgR51PPnXqfIRQU0nK3HztjqTSn7kt9cLe5fIkmwHKg=; b=WMci8ylGrv6wVanQE/QFwY7a+FwzGdh2OlIzoT+3Pgi4aCZIrqsgFHH+ETfNnWMlTn aXL7Qhbenz01W71G2KNsh5ulMYu0Nuy6QBD5WvpIDHTMEpCmxU/5EdStDqWsWlUucifs njZj6JaJZQAJQsTiEzbzTg7Cx0hkuxBEUJ4nLEusWn79KyTyJX/aSFMnyg4x54c1kYWA a92ulnPMlB2GkeQddrjw5sa7FBYaClR1rsIvD0B37umXq6+nNImuHP6FcpalXxJbHmdW qV4D2pE75TEcguB08I/Wd1wK4sFr1vQAXbRb8hx+DcgB2m9yVf6sCllvLT7cRUpBOkY2 XAfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766115518; x=1766720318; 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=qgR51PPnXqfIRQU0nK3HztjqTSn7kt9cLe5fIkmwHKg=; b=CXm51zJPMcSAlAF+xLb+WuTKee+CxD8Y9gigTOBfCtV0Pa9elP7HsWOqZQdKkdqMZw cYTgSxcbPtFjccBhxydytz4ueGswx5Eaw+rj2zJwrk8rd0mizE4zwF3Kfo7bmKpbq00j WPFC+mVSvDQfAf7anlCVvcdxOTy1tHgEAYj/8LTtBbtR9tyMd1VbCI3tQOSHgilHPsLX wp9i6a1+YpE0R4a+GO6JOkAI6aKTPVZ6M1mSy09AWRM4hlT3T/9vPYWRhuY2nV/ScMGG dRHd6AQJSiO3vufnnVOGULgiOCSIwBRB6hvfjVgm6hulHNr83kFs9RsjJxAjXOi7EB3o eOdA== X-Forwarded-Encrypted: i=1; AJvYcCXOtp7IDQgxoVO6FNcm4tF4KShiwZBCm3WPugP3Ges5WV8BDFN4xe7t7zemvraluz/evtBJJrKG/yitSATW@lists.postgresql.org X-Gm-Message-State: AOJu0Ywv9kIOFGePpPM7rLFJArEIk3K4RGkTq1MBj+FqAKVA8qxPRLK6 cmNL+buQaXqvZEYwpbgxJy2ZqHMsEHMqvOZ7awlBf09vL7iCEqtgEih03DglBH3MfsmjasrEiIh C3WoJkANbt1YGv6HG0rNux5XMbFzJfbVp0qfp X-Gm-Gg: AY/fxX49607tc8b89QtALfb8MIXeZOa2a8BElU4ATsqBvmP2h7g55kI+BNSGUycJga0 oIrBxsM33kjPMPJSgt4W42DaZBfIvv3XW0ayAnXZq6T46CaysCXwpAg79YhgdwugmDvy5KQl6RZ HH2I9pQDChHQOsYYr9id25qBU2mXPcezRrOGBbz/i+hwW48eiJFmV7oL/mhRlZmxsJGgMxX8+hh Qc2328QHv+17NQPsDCbTmGvNMcS0s9+y+XAQziKV57zCyoCwnBNfetf5ANA4xfpvG0K9Y+H/xq8 pTy5DSZjIaCRnnGXEW1BZmxwFGx+qI8mWB/mh41rMpx6fCaEDl4SnbQsQvb412YZVwH2170= X-Google-Smtp-Source: AGHT+IET6Kw8165+x98CzjQmBVwVUt0a1v2mEDZdnRFm4thtguvm6pqaGgYDpAO0gBhBgybTh2gqkSSm9jGygyAhw0U= X-Received: by 2002:a17:907:2d27:b0:b72:7cd3:d55b with SMTP id a640c23a62f3a-b8036ece492mr167229866b.12.1766115517745; Thu, 18 Dec 2025 19:38:37 -0800 (PST) MIME-Version: 1.0 References: <2wk7jo4m4qwh5sn33pfgerdjfujebbccsmmlownybddbh6nawl@mdyyqpqzxjek> In-Reply-To: From: Xuneng Zhou Date: Fri, 19 Dec 2025 11:38:24 +0800 X-Gm-Features: AQt7F2pg-OHA75LVa8rk7k3Q3xNxL9i9a10qtNsVjHOUMtKY9dQp3RUZ2dQSeA8 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 , 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 He Melanie, Thanks for working on this. On Wed, Dec 17, 2025 at 12:59=E2=80=AFAM Melanie Plageman wrote: > > On Wed, Dec 3, 2025 at 6:07=E2=80=AFPM Melanie Plageman > wrote: > > > > If we're just talking about the renaming, looking at procarray.c, it > > is full of the word "removable" because its functions were largely > > used to examine and determine if everyone can see an xmax as committed > > and thus if that tuple is removable from their perspective. But > > nothing about the code that I can see means it has to be an xmax. We > > could just as well use the functions to determine if everyone can see > > an xmin as committed. > > In the attached v27, I've removed the commit that renamed functions in > procarray.c. I've added a single wrapper GlobalVisTestXidNotRunning() > that is used in my code where I am testing live tuples. I think you'll > find that I've addressed all of your review comments now -- as I've > also gotten rid of the confusing blk_known_av logic through a series > of refactors. > > The one outstanding point is which commits should bump > XLOG_PAGE_MAGIC. (also review of the reworked patches). > > - Melanie I=E2=80=99ve done a basic review of patches 1 and 2. Here are some comments 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 // Corruption check 1 if (!PageIsAllVisible(page) && (old_vmbits & VISIBILITYMAP_ALL_VISIBLE) !=3D 0) { visibilitymap_clear(...); // VM now cleared to 0 // but old_vmbits still holds ALL_VISIBLE } // ... later ... if (!presult.all_visible) return presult.ndeleted; // Not taken if presult.all_visible=3Dtrue new_vmbits =3D VISIBILITYMAP_ALL_VISIBLE; // Want to set this if (old_vmbits =3D=3D new_vmbits) // Stale old_vmbits=3DALL_VISIBLE, new_vmbits=3DALL_VISIBLE return presult.ndeleted; // issue: early return After corruption repair clears the VM, old_vmbits is stale. The early return can fire unexpectedly, leaving the VM cleared when it should be re-set. Should we reset old_vmbits =3D 0 after the visibilitymap_clear? 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? 3) Comment about "only scenario" The comment at lines: > "The only scenario where it is not already dirty is if the VM was removed= =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(), b= ecause it may WAL-log the buffer and XLogRegisterBuffer() requires it." 4) Comment clarity Current comment: > "Even if PD_ALL_VISIBLE is already set, we don't need to worry about unne= cessarily dirtying the heap buffer, as it must be marked dirty before addin= g it to the WAL chain. The only scenario where it is not already dirty is i= f 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 mod= ify the heap buffer=E2=80=9D/=E2=80=9Cno heap page modification=E2=80=9D might = 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. -- Best, Xuneng