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 1osvWe-0003gt-ET for pgsql-docs@arkaria.postgresql.org; Thu, 10 Nov 2022 00:34:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1osvWd-0001Lj-9j for pgsql-docs@arkaria.postgresql.org; Thu, 10 Nov 2022 00:34:35 +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 1osvWc-0001LZ-Uw for pgsql-docs@lists.postgresql.org; Thu, 10 Nov 2022 00:34:35 +0000 Received: from mail-vk1-xa2f.google.com ([2607:f8b0:4864:20::a2f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1osvWa-0003cF-J4 for pgsql-docs@lists.postgresql.org; Thu, 10 Nov 2022 00:34:34 +0000 Received: by mail-vk1-xa2f.google.com with SMTP id h16so52143vkn.4 for ; Wed, 09 Nov 2022 16:34:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bowt-ie.20210112.gappssmtp.com; s=20210112; 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=K8yJGJLa7R48DBaOTlDf+f28nVZZ5pa3Zd3WTYfpJ+k=; b=x+Bq+frUeSM1jA62AnJU9P69CYouZzLksiEwwLfHboZiyOJBYv02XoXjL8JECw2Lib JzInI2MDy6T+EXch8W+AHASkY4CSug+3146Ho8UmaTftgZ/qSZ95iOn/NjiJzi8sXTWv bGo/anFxrN8DL2uvIqyWE7W5w5c4GNyjIcXZf+tqnEuK4s3v4CAMuL+xQFrIyxECfLVx 9mk4oQPBggtFqY85GdQTf8lOce7fEhRBDChke2+kWvzlFB28KqET5nxz6XZK3X3Sw+g/ XgVn8LKHi2Q5xuE9WZVUoFQOmyrdsAUuuisMw/2Niup37pppCZQkC9iF8raijQcJbJYZ EoDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=K8yJGJLa7R48DBaOTlDf+f28nVZZ5pa3Zd3WTYfpJ+k=; b=MgIHisRjOlQiKzD7+DInCN2B4GFav2HIcQUHINsWUqf3Y9Sn91q3XtLRx559Kb3ffn mqqfuQHA0NBm4rRlpin81q2hpssksyngMt0C0BGtJsr0cuAHSobmp01EH9Vrvqs7dPQ2 +XOE/LZVPKIgvI1hTuDDZ3cLhzP0JzsF0QUtb/Y/aXXaGlIdQDob0Qsd10X79qoAdK8D qsRVV0hYrT6uHOaiFwvQRSFJtCnOW1Ak0Ns+vtTOSzgTBE/ooTQtdqDXToEl993C+xk2 8hZgGdJXQPlPaYjXlGFQy1blplEXOf1J3rLudnisKsQ+l59D9itCs9JoPPwaRd80y69Y /fOQ== X-Gm-Message-State: ACrzQf1v2QQLRwoNfxt0Ej4GaSDMzA14uxVSc+eK7YwBoakCx5IrHdVU q5m3pjEEboe7oAGnxUl1NqzUyo0utR4PBmsF5YSONA== X-Google-Smtp-Source: AMsMyM43RscBWTI7+TryeEyw5cX7m3euajd9C6Z0dUkQX3cKubbSseSj5mqjGgPY80mWSlCvSx56jFfZI74r8XKhaY4= X-Received: by 2002:a1f:2658:0:b0:3b8:aca1:c849 with SMTP id m85-20020a1f2658000000b003b8aca1c849mr11587143vkm.1.1668040470592; Wed, 09 Nov 2022 16:34:30 -0800 (PST) MIME-Version: 1.0 References: <165764161026.666.13998783616221095418@wrigleys.postgresql.org> In-Reply-To: From: Peter Geoghegan Date: Wed, 9 Nov 2022 16:34:04 -0800 Message-ID: Subject: Re: 64.4.2. Bottom-up Index Deletion To: "David G. Johnston" Cc: hus.mhd@gmail.com, pgsql-docs@lists.postgresql.org 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 Wed, Nov 9, 2022 at 4:06 PM David G. Johnston wrote: > Ok, so the "most recent live tuple" - this in an update, there has to be = one. Can that live tuple that is being updated ever be removed by this pro= cess? No. > I'm not sure what the long-running transaction has to do with this though= - we are in an update so we've locked an active tuple and that is the only= tuple this coexistence is talking about. We cannot remove "recently dead" tuples, which are definitely dead (they were rendered garbage by a transaction that has already committed), but are still required by some snapshots. We know that they're bound to become garbage that is safe to remove sooner or later -- but it's not safe just yet. > You lost me here. Which tuple is "it" - the one we are updating got dele= ted under us? No. We delete any and all tuples that are found to be deletable. We don't care about the true reasons at that point. We're perfectly content to be the beneficiary of a certain kind of dumb luck if things go that way (though we'll typically see only a few garbage tuples that originate from DELETEs or aborted inserting xacts). In the end, we're really just ranking heap blocks, and then visiting them in the hopes of finding that we can avoid the page split. We're choosing among heap blocks, not index tuples (once we visit a heap block we'll delete any index tuples that point to the heap block and are seen to be eligible to be deleted). > So, the page that the update has to be placed on gets picked for cleanup = but the actual fetching of rows and such doesn't actually care what that tu= ple is. Though its ancestors are likely to be picked. Yeah, heap pages pointed to by relatively many duplicate index tuples tend to be visited first. So-called "dumb luck" is more likely than you'd think. There often won't be very many heap pages in total -- in which case we're bound to stumble upon any garbage tuples that weren't actually rendered garbage by an updater in passing. > Knowing for certain whether the cleanup scope is "just prior versions of = my update" or "any old versions on the page my update just happened to be p= laced on" seems user-facing worthy. We don't particularly care about what the incoming updater that happens to have triggered the bottom-up deletion pass was doing. It's not special. We don't particularly favor the row being updated over other similar looking rows on the same leaf page. We'll usually have to visit 2 or 3 heap pages total (per bottom-up pass) in any case. > I'm almost thinking the last sentence "Each new tuple within each index..= ..for a short period of time..." is doing more harm than good. Removing it= makes things clearer. I'm unsure. Does anybody else have an opinion on this? > Bottom-up index deletion is an incremental version churn deletion process= , triggered by an anticipated "version churn page split". This only happen= s.....(the rest can probably remain the same, though I suggest moving the n= ote to the end of the section)." Probably the most important point is that bottom-up deletion compensates for cases where the HOT optimization wasn't used, though only for those indexes that weren't logically modified by the UPDATE. It more or less takes over from HOT. But it doesn't necessarily help at all with DELETEs (not reliably). > Adding "no-longer-visible" at the start should hopefully be a sufficient = reminder for someone familiar with MVCC; or a clue that more reading of pre= -requisite features is needed before understanding this internal part of th= e system. Yeah, it's not clear what the prerequisites for reading this material should be. It is part of the B-Tree internals chapter, though, so it is very advanced material. --=20 Peter Geoghegan