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 1w0SBZ-001v3N-1m for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Mar 2026 22:37:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0SBY-00CHDE-0E for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Mar 2026 22:37:48 +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.96) (envelope-from ) id 1w0SBX-00CHD6-2b for pgsql-hackers@lists.postgresql.org; Wed, 11 Mar 2026 22:37:48 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w0SBW-00000002Cwj-0Mdi for pgsql-hackers@postgresql.org; Wed, 11 Mar 2026 22:37:48 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-7d74aa6bcdbso404144a34.2 for ; Wed, 11 Mar 2026 15:37:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773268664; cv=none; d=google.com; s=arc-20240605; b=REesw7tXqLvxDr0ClJCgPkRBRQLHvh2PUOoPBQyGHbD71WHx1pSZy7A7E/vr2+ndiK lfapHY5//cHvQ9m2Nx1+vI7BSoRNHYSoOoqb2Qn369ZXsXbyOFBtLM/FpGL0dOZAhV2z 12V+lv1B4jsArcdNtysb9nxhZlMPet4kD0KtQ4DgtbHWlX4MK3CEYt6Cuw4gvR82UPyR JoEC7TlMY6qIIUD5034Aizo6p6+7kPovb24R+Gy7VG9mHCc12kMS0WMYEurczUXujrK7 2n+gpELZQr/AhF/A/V+P/2o0jgh9rEvF9u84G4AGwgjldHRWmDO4k5MVq0BxlMrVrvC5 /E0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Zs9HmEyGJkFsZOONekOAL8xeaY7/dvHETw8mbfhKQxY=; fh=P6J62LipCm6x11CBuNiWqgDqpvqkDS2tuGDYAFuZvSc=; b=NZo223W9Gp5EwP2JUVek6LUd1of/KuRPhivkOuD80d5LTvjj7vZGxaPMPEJrbkFYU5 S/UFQFrL7VFtezj/aSPKtfAshD3LctgzTDVnAqoqwPV5LSxOnNooi6dpjgIL69BQTqZs rx6vDQHfFpgJQyvUwJ6S0ngL5LxlpA5+eo6+jTKktmHUzT7n5s+dZB8l26c5cQKA9EOK KtCRXpkVlVWuLrsM/cGbv3Y1zb88h4PjPdwA5l0Iis5qfw9aoxu8cxmQwQI6Tn9tXVON XkeFbPEUsXRnGJv+G32HlDR5IeIYHmNnO0RtmuwdXUE9kzBwYh1/a7KQHO7FJ+WGgYzD QESA==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773268664; x=1773873464; darn=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=Zs9HmEyGJkFsZOONekOAL8xeaY7/dvHETw8mbfhKQxY=; b=bEZe+/ik1ItL/CiF6OWsleQrNXg0kI7FJuVcPmScIK3iHnWgBEfdaIKkTwsRkTUStV 2LDOyhFwvXPqO5lUS56h5wv40aPW/XhqfcpkYXxdBdgd5JxkzBMaTam/MK1Cee04Pjfp h6GWXeYF36yi4I34YbHi1q9vhj/NAsDx4mJbKLvpVIp/xBH6pDDN3vkVPGNFb87lwkMW DFrL4yl98q5D5fiNc35s4aDPrM9aFWZlGKxq2I9ERyphtkrKALEEgGjXNn0q58gd+yA2 HZyBhAvhfmznltsYTAP96dxxKFnBkQJAwWLPD7ULwf86OGjrCh+6+HvX0ZYhevxMCg94 w0TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773268664; x=1773873464; 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=Zs9HmEyGJkFsZOONekOAL8xeaY7/dvHETw8mbfhKQxY=; b=nbWnOl427h1R3ATs9tco5N/z06PbGh7eKbcug32q2hUZGxm1NxBxUm+Ql+Zx00xXH2 FsD11OWHVELV2yTPcUfUg7rYT/1tdu5EEPwQQQ3SYCdbuTeyS3eooNAb/Qvdvm/UKmQm 5FpfXmvZl49cdvuTJupEQQMg5KSXAX4ZnWdMztyrMTkskxHGmUv9UMfCkWcUgCTD3oh5 wRQGKd3yh2OHWBZTUcLj/8zCMJqEoCB+K9HUZSrXP1Bmo/xIuc4dw/owOHZQeCMhBLYC zHrSCkt3kPCRwZwD2PlpLTR/qjlhM7WhkuLgEkHpQ43aCAwX2LcKMU78AGOh4ex7wyRc IU+A== X-Forwarded-Encrypted: i=1; AJvYcCV75ViHbW2M31W8BimXw2o3WKQIqkOmlz5uvwyKTZV8H2aiNYfp0wdHd6+exHuvHeU6MiTZXe0CKkzoBwXr@postgresql.org X-Gm-Message-State: AOJu0YxnRkD8xFnfQUnEA6cZ6YQC8zun2aqdK6bhHb8qZrwoGkb8qvPj 5NVPr88HrD/lD1pSgSOLMESCsx72GRsfo6KTUMmJNq1W2rNUCIV4GotvZoIWbhEIo/LEuYv23Bp 0ntnaGPCZfcea/dCWdxkRApvJFSDpSXg= X-Gm-Gg: ATEYQzyJs40gS+WscZZ/Vd5TyLFpYVvompw4Mcf1fqhUqO+8nY4Lk8L+aygn3hxYyiD 7rZxlMCMiKFhJ7Eckn1tBzzq+VF8GK9ymRCHxCHmf9pA7UMMmXA+oZU/KqT8cUypPYr+KfGXFN/ ydyPG3MizF6S8EYgGxBNBifngx3XTwKleTL78h6rhbjsmx3xe7VCaqVo8zkbGSDMiXLO+S6p8o0 Jrhx3DZqdo841g/yJ3GzzWu2GohgroHehYzsdQ1WQ82Syfy3ZluuKvhJ6ttMPijL2MLXiCj47h0 6FSKxCW3D3BUm7DGfOywuFSuyFRkFBWslxrlRLvqDGXE1gm7OvnNkA1ZrZL/7CeYjBouazFpS5w UNZNZYUN1ynDlpwYGjTgK/ua+vMYgHnyVKP1iAsY= X-Received: by 2002:a05:6820:16a6:b0:67b:b96c:2728 with SMTP id 006d021491bc7-67bc8a764a6mr2624734eaf.63.1773268664526; Wed, 11 Mar 2026 15:37:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Alexander Korotkov Date: Thu, 12 Mar 2026 00:37:31 +0200 X-Gm-Features: AaiRm517PANEi38DaA7T7-fuaoZ0Pu4g-pPp3yE6BBzUbvlq3VAl0On3D4CtVPE Message-ID: Subject: Re: Odd code around ginScanToDelete To: Pavel Borisov Cc: Xuneng Zhou , Andres Freund , pgsql-hackers@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 Thu, Mar 12, 2026 at 12:35=E2=80=AFAM Pavel Borisov wrote: > > On Thu, 12 Mar 2026 at 02:22, Alexander Korotkov w= rote: > > > > On Tue, Mar 10, 2026 at 11:29=E2=80=AFAM Pavel Borisov wrote: > > > Hi, Xuneng > > > > > > > > Is it worth/possible in recursive calls of ginScanToDelete() to f= ree > > > > > allocated myStackItem->child after processing all children of the > > > > > current level, when they are not needed anymore? > > > > > Previously to this patch, palloc-ed "me" variable also was't free= d at > > > > > recursion levels. > > > > > > > > Freeing/reallocating it per subtree would add churn and make the > > > > lifetime rules harder to reason about without meaningful memory > > > > savings (the number of nodes is bounded by tree depth, not number o= f > > > > pages). We currently free the chain once after ginScanToDelete() > > > > returns in ginVacuumPostingTree(), which matches the natural lifeti= me > > > > boundary > > > I proposed not freeing child when child iteration is complete. They > > > indeed can be reused. I proposed cleaning children when "my" iteratio= n > > > is complete. At that time all the children iterations are completed > > > and not needed when we return level up. > > This is not clear for me. We need stack items to keep track of left > > pages until we scan the whole posting tree. After scanning the whole > > posting tree we can free stack items as we do now. > > You are right, that we can free all posting tree stack items after the > whole tree, as we do now. But I think we can also do it earlier. It > looks like all "children" items are needed and could be reused only > until iteration on "my" level ends. When function returns up the > recursion "my" level becomes "child" for a caller, and previous > "child" is not used anymore. No matter how many levels we can go up, we can still descend and need the leftBuffer stored at any stack level. ------ Regards, Alexander Korotkov Supabase