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 1w23Mn-000q1E-35 for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Mar 2026 08:32:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w23Mm-008Qfv-3B for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Mar 2026 08:32:01 +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 1w23Mm-008Qfn-2D for pgsql-hackers@lists.postgresql.org; Mon, 16 Mar 2026 08:32:01 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w23Ml-00000000OP6-06Hn for pgsql-hackers@postgresql.org; Mon, 16 Mar 2026 08:32:01 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-6630858b4ceso6049102a12.3 for ; Mon, 16 Mar 2026 01:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773649918; cv=none; d=google.com; s=arc-20240605; b=LEcGD1bPps/bTFbAy+wt2jQ3sELKhsIzzvbUXRwRZN3dZLuO28QoetbT+FoOV5bcAt 5EGcEw9QnBz6Yg3hPCcVslBWtCm/dGFicXAwteiK5ny53QDZMc8uT6QJg2YmdKGAE6nD AXQtwCKnpzWYjKc0TjJR03wnuo/a4p2VgukziQpKogfWJ+P3lqikO6+Wy5m71e3upvED uHHiQW/ZAkLRwTMrdvDFGo25gXjw3pJJG8f1SUFbPgHNwbJHYvnYYvLAeHFXdMGYMf/o 1w0Tr/fdD3YxrHgt1hyFjjbZ+oKpX+FZm5Tvm/yh28p4ZgtkHSK3rHtIJY4omC8a2iRQ r8PQ== 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=NPDWy92XKC0SeDjCGfDHOtJLrg+cJRLgIcBPKRFrs1M=; fh=oRcC2ugv3sjbsRUXX438HmQtbdfpcvjbbMN4GzXL/Xc=; b=ASLQ/F+ujz4ytzArHKCaIBV0uDJAW0gIa4A6SO1Fw8ZRuoIjaB/ukAIYdPqJTXrnag s9D9bmQpGYsuII0gLT4i4sCJW7pT+g4bCZmd+KuilsZ9E4ijyDWeViuk9KQmicCuQYfd OYptn6hhbqR3JtrPDFdSFVonMYr5v9UYtBME0d+SCFeXlPOaieEKie/0HERjtTlkX17v WEkCyCle+iOoOEtKpVGPyU9u6PuQPMFuSf8bSIT7f1030vEoXttfoZqwiiEOFlVSA1qG WPmuzahkhSSY/aX3/zgJMaSZdBtXTHrU1IZ+DxwpJeFs3tINMcqscmNTmX9JPuwcT6cI VONw==; 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=1773649918; x=1774254718; 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=NPDWy92XKC0SeDjCGfDHOtJLrg+cJRLgIcBPKRFrs1M=; b=kNMObeHgsFceZsLMQ+Cib+28jxIEsSPyZY6UuO4TEjbpAky/h1R4rIZahbFpPtCVFm v4kHw/RhVuzc2BwZriVUAui0F4lxCcvhcBne7uCTeJRwXTcgmVT5bo+WuNw6Bja2pwo1 UVOb9l6HjhpHq4G4uax8Q729ecyugovNuvKInz52mOEcvisBRxqXOb0k2NL/+rluiDka ZI1u2xAM/D8yWhFm1jgbqAFvVpUQHYfCEuT3UKI9xVJqltKSBiT5XYyI4Bl2HXEFRtN5 54AmcsYwXHDgb53WJuy6Ozb6X4ZIaiod3kq/j+mp8OgNXr518qs4QTpGA1mbS5/gCIha DSdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773649918; x=1774254718; 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=NPDWy92XKC0SeDjCGfDHOtJLrg+cJRLgIcBPKRFrs1M=; b=rw6hPCoZAZ7JNUo9EeUDvFYu7EpJOpTD0pmvUoaU/FhWBp24Yzo6XeIX0APlNSc2w3 DBKnOWefkS7bNJU71uajeXVNSHr4HbwelPUNz66P+kfwthXoixA0k7/aUlOtOseYKKMu 8c30t51wOiXbMay5Ci4FVGOOW3/qxqFpL/VyjpQzEHi0c09z/sd3R5t1K/drXAJ9dLMq 4EsfxnsLekj8n61456Uvr4GDwLKGDKRHxLKo1eBVB6QjnOBWOOvy4LG/FcZSiI4ZQOL2 r8PstnHWGKXZdD2A5yYsGOEJzNeTgZiJBasAp0yDiKXAViyP2u0LbmLXKyzzEIps5/SH ytXg== X-Forwarded-Encrypted: i=1; AJvYcCU+opgVSefdYHe3JgYLhnGqyxQTlf5BJGc6NVJSfLzNLFui0gN3GxIvCKP/xelmXvSkPldpmDRbLwyRbph9@postgresql.org X-Gm-Message-State: AOJu0YwZq36p22NzOQzYsckkYSmUn8yHxuIbUAWTvVF6uHcrP1srJfEi vmNUHAc0JZgFQmgU8tsUdwaQFhrjJjNJzj1nK3gSjPUzVJxaYEAsJSheuYnGnkkAuZzw5NJEmlx h+dOOs5to+fQiOixhpi6sdj56tYSzPOs= X-Gm-Gg: ATEYQzwgbMzA2PRpEgqeg2VYBZ4gBdOJrZ/qdEGJjYvPXNc3bcnlccHkwGDaUU0ny31 16pN5Z3GHH6n0MtKFYuXF0RXPNTNn16DIRt/wTl89DhqGtW8BQqonVrFsPxOAoh868BfBp/jOL0 PIS7pQsFGAmxXPc5QqhjblvVpg4REXt855JzI2Fx5JO6R617yIhJhyQGdS9xCHWymRJ0eLttpRR nB/DkV59Bwtz9XQ79QyX5SrxkRoxlLfD//dcEtk9FgZJzqQyqbfuN391MEU4MLcmjBvd7IpoYi6 tmuufmzBRBsu5kJGdYT9wsg1WcRl9JD2jXLlLU5SsIB4wBk1773Do44Is8PJmi6VNprtpZjMhk/ oaM9oj3I= X-Received: by 2002:a05:6402:26c6:b0:666:d8bb:8607 with SMTP id 4fb4d7f45d1cf-666d8bb88bdmr217785a12.0.1773649918176; Mon, 16 Mar 2026 01:31:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Xuneng Zhou Date: Mon, 16 Mar 2026 16:31:45 +0800 X-Gm-Features: AaiRm50XdBPRTNSiqVBvfEPDalapl1Z89M-6c9E3oFkXmRTVSVEQArO6RqAkbCE Message-ID: Subject: Re: Odd code around ginScanToDelete To: Alexander Korotkov Cc: Pavel Borisov , 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 6:37=E2=80=AFAM Alexander Korotkov wrote: > > On Thu, Mar 12, 2026 at 12:35=E2=80=AFAM Pavel Borisov wrote: > > > > On Thu, 12 Mar 2026 at 02:22, Alexander Korotkov = wrote: > > > > > > 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= free > > > > > > allocated myStackItem->child after processing all children of t= he > > > > > > current level, when they are not needed anymore? > > > > > > Previously to this patch, palloc-ed "me" variable also was't fr= eed 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= of > > > > > pages). We currently free the chain once after ginScanToDelete() > > > > > returns in ginVacuumPostingTree(), which matches the natural life= time > > > > > boundary > > > > I proposed not freeing child when child iteration is complete. They > > > > indeed can be reused. I proposed cleaning children when "my" iterat= ion > > > > 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. > Yeah, the important point is that a stack item here represents per-depth scan state, not just one recursive invocation. Returning from one subtree does not necessarily mean that depth is finished globally: the caller may move to a sibling and descend again, and that later descent can still need the child level's saved leftBuffer from the subtree we just finished. The stronger condition is that no more pages remain to be scanned to the right at that depth; the code already uses GinPageRightMost(page) for that when releasing the child level's leftBuffer. --=20 Best, Xuneng