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 1w0S9T-001v1H-1h for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Mar 2026 22:35:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0S9R-00CF9v-2c for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Mar 2026 22:35:38 +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 1w0S9R-00CF9m-1j for pgsql-hackers@lists.postgresql.org; Wed, 11 Mar 2026 22:35:38 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w0S9Q-00000001gC8-1GGu for pgsql-hackers@postgresql.org; Wed, 11 Mar 2026 22:35:37 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-660a58841d4so397269a12.0 for ; Wed, 11 Mar 2026 15:35:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773268535; cv=none; d=google.com; s=arc-20240605; b=fE77itzyVOH0+SvC5P98pItjMp+zrohH0hT8XNH0LiL2mzFxuhfN+Qx0dV/gegxC5r seZ6biz1byJRwgYq1I4nYqPYysIzVcwovlS/lJZOTOmsuQCTlmTxL9aeJcKlCJIyE+m5 kx2vESO+NTcv6nlvioWMdTDzOoeMtBaEmLkLEjt9cfG5d5c3yGvmD33CJJ4pFVFC+eUC JSUFr9tI0k/aFA9E/JaH3wWdW6bTS963x1QOZAFVaBtODlILA9O43r+slC2xjB5WVIIi cMfY/wnj6Kr0ZLEEZD0YNj7D4ne3v67Ocr4Tgf4piD4TvoLdLxiNKtcCPcvsAlXn1zh8 IU7Q== 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=ZEiuAl9aj1WSP0sf8YVDFV8tZFYGedupB008CVQ2NA4=; fh=VbGZcS6bahnmsC6ezhurWjGBAoXd9yjbMwe8UZbTx6k=; b=OgQQgUV3WgDWiz06TpSfIIvU/I/Hj/uoaQsLP9BlP3t2BDhRLgfjPQ3mcfQojbJiB8 gMpa0EVSQ2KurDijIJ2ydFSw440Z20qbO9QxEEVcex5ajl9lOVs/ido/CqW4ndRKvpFQ YHLegTZM8n0YcJFxm48tBhffrUCwWe01W106nW2zkRYtY8tdcHYDHaBmAlA2hvXYOXj8 06gyRcfgqU1ZEo+0fHjb392DnLPu6+W9OApoHkWccWY5qrKMTWDXnvfVO9FpA75+5oNf huq/MxbtZIX0PSspKwfc65wpHdXW52J60VoNCkN8Xae3hs6MYv9i1jaZGmdy6FSpWz5U fqig==; 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=1773268535; x=1773873335; 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=ZEiuAl9aj1WSP0sf8YVDFV8tZFYGedupB008CVQ2NA4=; b=aYqVmgTyjntbBZh5V+o7zNOrFWinVVW20NZv+/CbXAleqOMMacqCbkMCP1u1wTRTr2 7n3YNfrW/YeWe/jv+3Egj4RHXU89pENjTiUVIX30PBxA0ZYRgvOkUMJqxqiU2QVOgQsJ DYB8xcs0WcdIw/7U+vUCaVc2ddDQSuMphC/aSRYQjG+QjlWY42TvgARShFCbqnMZ5Sg4 ri3uqVhhfMzzfzukzLGcS60tnenElRfrqMgMjk5p9lqm9kz/dp4yxvO/fjUD0x1BrjZ+ bukCgvompk1LJey+t2e+RjVIbN7koHPGlvbyvzZHwjn7/KSLDiU/Is086xjLTfJzYHJw hm2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773268535; x=1773873335; 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=ZEiuAl9aj1WSP0sf8YVDFV8tZFYGedupB008CVQ2NA4=; b=pMjrzQDa555iTsW09yGopcb7F4uBcSxm4ZkT95OC/3ArRsC0Kmz7uWC9cPhPjstmlw ORMrIPMDkJSTynoB/w1ZeNjFbdptPi8PALbvUbUbpJjiGftLVpMD2pgHIPr2NOLs8YRg yNxu/xsfesiYsFne2LuGic0nktYgwYhBQGW9l9t6Kc02p/7LR3gceuSZHdzF/XcaSBw0 pjkKduYXK53RFgwb9CXXqBIeOBmyS9yYTW8wR7+7HOeRhRcoVBjhCSAsZUARwCw4DK0E H8lyE9la6n7WimfW9v2vgyaLjsdd3qh4wsAoIXvZAzSanQKPvu8Gp3LDBJq6oMj0V9R+ 5hmQ== X-Forwarded-Encrypted: i=1; AJvYcCXcN/4RGd0qPK0lceOeU++cQDMviodxT8ADXGdg0TGb0LW3uvrTtB5aNtZUD13rB6BxHKWWUzqR4dKjxS5j@postgresql.org X-Gm-Message-State: AOJu0YyI0sVvhkK1ZiOI2Sb1Nf51WEHYRaWDnDL0NUI25D7IADeRyTIa HNaSP8RUOuZht9NvAky3VaCr7WEratMt5jdrhdGct3+rJmCZKpj9T/1BuQelBKRnj8j2XpiOfMN pa4TJf8zqQFfxtN9vbeU8FyZedT5o7suyBw== X-Gm-Gg: ATEYQzxRGaKk6BTL30LJcmPtqmsqe21S2pEHXWfH/YJivDDH/h91XTbvaYvuhe6gleE 0kjMv8ojJNWW5Uhhu6S+senR8eCV6/4jEgpDTCxOamA4XHzt+exCSsqsqf2CZJXOTL6j7VeHa67 x3StUWcLUqrznmZEUcBH7VpmoQ/cYFiFbr9tmIAG91M0kpgjLVk93tnhy1rZ+6vC7iicgGocKnE bo0/maOHVpqwKhmYdtd4GqQsASq+vbUzdt3/9JCA5G/kkhbUd3i0dX2qNag+S4n8pgbjSfy/I8h 4CNcl60IEg== X-Received: by 2002:a05:6402:5109:b0:660:f98d:227f with SMTP id 4fb4d7f45d1cf-66319ee21aemr2196379a12.28.1773268534712; Wed, 11 Mar 2026 15:35:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Pavel Borisov Date: Thu, 12 Mar 2026 02:35:23 +0400 X-Gm-Features: AaiRm50Pxi37W6PoVkSye6yn2I4BlwPbYcSvX7vKYXhpCnn06edJHLMMdQvREY0 Message-ID: Subject: Re: Odd code around ginScanToDelete To: Alexander Korotkov 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, 12 Mar 2026 at 02:22, Alexander Korotkov wro= te: > > 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 fre= e > > > > 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 freed = 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 lifetime > > > boundary > > I proposed not freeing child when child iteration is complete. They > > indeed can be reused. I proposed cleaning children when "my" iteration > > 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. Hi, Alexander! 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. It's optional, maybe we can do freeing at the end of posting tree iteration= . Regards, Pavel Borisov