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 1vnOxG-006Xda-2w for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Feb 2026 22:33:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vnOxF-007giW-32 for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Feb 2026 22:33:05 +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 1vnOxF-007giM-26 for pgsql-hackers@lists.postgresql.org; Tue, 03 Feb 2026 22:33:05 +0000 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vnOxD-00000000QW4-3EBY for pgsql-hackers@postgresql.org; Tue, 03 Feb 2026 22:33:04 +0000 Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-7d18d02af68so4034815a34.2 for ; Tue, 03 Feb 2026 14:33:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770157983; cv=none; d=google.com; s=arc-20240605; b=UJYercKLoYeygBwvRoa0reJtzq1y/ySq0sToy5+rQqmtGSnd2nJgOMf1XcIxa81jxf 6ejKb2Q5ekYHGr0uf2EAL7GXNhvD1pjtgpAig7oatH6/UsLIoig9077hHZApw1BTX2FW jyIdmJQj1SRYN6cNvmYgzNWtuCAAaObW8cegf81/ofPO+R9buv2AVQNrPCof9YMcSRDZ vyVt8IgJDRwWysdprbVveRb26gL2rJs5+ezG27Bua8NvO1NrrzvImFCsjCa+qCeCymcB HYwLaKoNb50KrIPwJmMpWzv/zkyjK8aBxzAK7RH5CWjUQcAFcvJxdQZex0dHZIVjBDyT SL8Q== 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=BgoWn2HSQLPYANzOV8MFjWWG1gdxRqK/bLqORKX3Yug=; fh=ab2QULvDsfAQZSkQ0LbXUMmEfPg89lFn2bauBsCokMg=; b=lgFRkkV2Gf5pjJ6fxZYURhnmmDhrt6lKFC3FRUHsehlzaRruDFHx3NlJTEC7l2UmLB ldYZ5NYsal8oQocguYPTkznAvObl6w4wbodSTQadkKzvcW8xSnmUM1dQS28AebXGeHWO NYdgOkS5a3CFOH7Ro9SO+Qzp5rsRkIyOS3PX8Y90emMCuU3+Indh3aS3yj3BMpcHidAp M5VsaBO0tHcYHn1nFAsp7aNnF4e9EpMdzvcBjaoGZAVV7LrESTBlowPl1BjjlpRaore3 OjwWdBiMKQdShcsI4mN4iuxQUNFNA145J3tfUA+crP3ubdlSWbW+94iYMCFKoa5GzizG 3mag==; 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=1770157983; x=1770762783; 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=BgoWn2HSQLPYANzOV8MFjWWG1gdxRqK/bLqORKX3Yug=; b=aQnDpODaOrB2NRKY8OsZEaRdgqTuS5MPR2xc7hNc4j3THnBTKdEq5gGP3XDTmIJfks ldkjiPHL1GHgnoA/73ElodBH8D/a4xAWSFtz00dSk0u9qYg16K3bBkw4keuaSmDTC5/Z SCDnbxkyMoF7a4ShSvRmnR/dF+OCmr7LPmhy8Dmb3QJuWobJQybZWv6jmAwGK9Yf8bd8 W3b7oB4KbULJ7XqB2W7TqoYE0XHF69tlGmipcDKSs77+4/Cg3aT4kzTduG+Jv2jGMxDt PvkZVOv49lQsdS1XpUEi54/YTT7rvjUiLFAqMOZMScaxx+dH4lrmFHvHvnCVEmUxqE3r NXgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770157983; x=1770762783; 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=BgoWn2HSQLPYANzOV8MFjWWG1gdxRqK/bLqORKX3Yug=; b=DFEpJAtaFBfxVEcWYInbvagPYdIlYicHjbI/bTwFTusUnSoo3N4SQFoeRxbHeYZe2E 3waGrpdujlmSstrycwYH3zkG7WPdcoLcTKS0ZuQcmJNBISJIvTuNGcRNdk5or1OFJAp1 nD0vD7Xupg8qnDKqLN1bYsI257l2la215N2uSmSQRV/rCF94pLbXR8qZzMTfj10czVzG R1JIx8cjrQ9HCEskhVxdrj3/pMLxUZmW63OY7e1gyB9sJJXpKjUnYtyn1s0IQ/k+qHyN 9+9iBxw0o6+acv5M+6xcWyGbo2EUdr4Gh/FpdBcEz6cJYu8pSqPFXSMDx9jOdLm8TpXG Z6rg== X-Gm-Message-State: AOJu0Yza2ep9ma35rG8hbYFJ/Lfkj5fRYYPfVG83ssNF/HY8HGlZr+AZ KDIKe121pnfKZfVbfSPjK1txluej263svcrXH3gSPoXMmgIOF7WyxOeYYdRbgJAetg80HsDIt0J 91vbeFU6CUM6LWU7hu4i1o2wtTtMPYNSmmo/y X-Gm-Gg: AZuq6aKeiYQCPdYi3oFXFSJ9ufjiV785ozl7g9+pWizsYTfpghesLcYk+fVi8yHEKC+ JKZsIN0gyXxJe8f7meal0+y/tPBJMd4easL/nOVQspOPnD5FEnVwPyTQfJce6+7vDNN4ULA1bsX FihcmgrvOMXa005uVLiqwcV7LZaAq5THB8ijaVDdIT0ix0uSBLg65dDW7v38b9UyXcAvWME410U a/I+xuXKcnc76zFnYtNrGhD5SF3/lpyQb4YzEEBvMlMoupz1XXgsENZqqibV/saPpEKF80VAtDe YATHtzl0NPE2CVJqKLGEX27OZEQ/DYrgc7pKguU9giQkebeqn/kro72r87m8/lXyLtG23spH1wg 1zS/g15cj3ibNWg02wpL9IYGLbu5VmTrbcdxegFE= X-Received: by 2002:a05:6820:623:b0:663:dda:afa7 with SMTP id 006d021491bc7-66a20692a59mr600804eaf.28.1770157982954; Tue, 03 Feb 2026 14:33:02 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Alexander Korotkov Date: Wed, 4 Feb 2026 00:32:51 +0200 X-Gm-Features: AZwV_QgPxhaDAqK4AWgO2GrX4lbvOzfXuHcHCnc2vMiPVNdlZzkSA3MppiySs-4 Message-ID: Subject: Re: Odd code around ginScanToDelete To: Andres Freund Cc: 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 Tue, Feb 3, 2026 at 6:26=E2=80=AFPM Andres Freund w= rote: > > While looking at converting more places to UnlockReleaseBuffer(), in the > course of making UnlockReleaseBuffer() faster than the two separate > operations, I found this code: > > static bool > ginScanToDelete(GinVacuumState *gvs, BlockNumber blkno, bool isRoot, > DataPageDeleteStack *parent, OffsetNumber= myoff) > ... > > if (!meDelete) > { > if (BufferIsValid(me->leftBuffer)) > UnlockReleaseBuffer(me->leftBuffer); > me->leftBuffer =3D buffer; > } > else > { > if (!isRoot) > LockBuffer(buffer, GIN_UNLOCK); > > ReleaseBuffer(buffer); > } > > if (isRoot) > ReleaseBuffer(buffer); > > > Which sure looks like it'd release buffer twice if isRoot is set? I gues= s > that's not reachable, because presumably the root page will always go dow= n the > !meDelete path. But it sure made me wonder if there's a hard to reach bug= . Yes, it's not possible to have meDelete set for root, because me->leftBuffer is always InvalidBuffer for the root. So the branch handling meDelete case should better do Assert(!isRoot). > This code was introduced in > commit e14641197a5 > Author: Alexander Korotkov > Date: 2019-11-19 23:07:36 +0300 > > Fix deadlock between ginDeletePage() and ginStepRight() > > I didn't trace it further to see if it existed before that in some fashio= n. Yes. I think generally this area needs to be reworked to become more clear, and have vast more comments. It was wrong from my side trying to fix bugs there without reworking it into something more appropriate. I'm planning to put work on this during this week. > There's another oddity here: ginScanToDelete() requires that the root pag= e has > been locked by the caller already, but will afaict re-read the root page?= But > then have code to avoid locking it again, because that would not have wor= ked? > Seems odd. It seems a bit odd for me that caller already have locked buffer, but passes BlockNumber making us re-read the buffer. But I'm not sure that's the same as your point. Could you, please, elaborate more on this? ------ Regards, Alexander Korotkov Supabase