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 1w7bQW-005W7l-1H for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2026 15:54:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7bQU-00B6Tm-2n for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2026 15:54:47 +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 1w7bQU-00B6Te-1k for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2026 15:54:46 +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 1w7bQR-00000002CIH-3ZUh for pgsql-hackers@postgresql.org; Tue, 31 Mar 2026 15:54:46 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-66a4c6bb6ecso10459167a12.1 for ; Tue, 31 Mar 2026 08:54:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774972481; cv=none; d=google.com; s=arc-20240605; b=ei1MF1KjmAGc4y5Basmui50VMEMm7QxEx4/LYu0QgDXB95mS52/C9/lc+jKTZQNz0i 7qJ94WL8mNHj2ljvCk3LMFD06mDxVCBFA4nCiIqvS7+WBKdzHHf4joerLgMSk1pNIeR1 tl3rsxDVU78n77vwhEjfeZSVMBgFVglI+/ufvxU2ap+Jp0ZKp/ZIe9Ptxdq0YyKxWB4E 0YWTi4riEvhgV3CjJcsc84i5GfbGndalbFCMv2s4ScmUFP1i6MuFruMh32Y7tH+mFxOi LwF1IKoz+d64kcacQLi1I88FEqMubdKmm63W0oFSmKZl2J0Lb9h1rItF3jt1qchHIod0 5HSA== 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=7TooFR/DlFoJ/jDYD9P1MJwq93UZMJ37xZotM7VxKmI=; fh=K0MgC3FHSOER4Lm85G+pY4C0w22ml4a0UEkDFYuHl58=; b=DSEB21o28YDTbm60nnsA7y0fM0jIocfT1U0WcoPSQ7pSl7P0MVvKmKaD46ckg0MVZA UEDwAHr6bjo1TA2yQvngZ0nxmdOedowInA0uOb9SnNlHTnu3DuHHilSrfp3DRdwQI/+u zvCE09FJLFeyZvng9OKz4RZhDuN5yyMHYEMRSAYSmXYPL7qFHTQtJJJTt03q0utlnFFy /HpW3kZF6vuGxBCFNm/pv1fsaxy3lfpvmVRW2tz//SHN6NmZ7ej5qCoYJBZ+QmFJGgHU O8QfS+fs6dP4WnZStHbIVVebrlwKONhuLkCjndncfDaNGCM+03kYslY4FQoMXsIS8feN GyPw==; 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=20251104; t=1774972481; x=1775577281; 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=7TooFR/DlFoJ/jDYD9P1MJwq93UZMJ37xZotM7VxKmI=; b=aIWsUQWYEDQUTGy6lbrSi0NO75taUxFodtw9xbZybkDSRgRzDbPYtHSqmNySwLQG9d O1fZlHuR3m92JLKJGnTaxTMV/P2K0N0qKfUVuRoReVbt1WKCSAyGiCexH3WmzTgbzi/p 0Qbehhc6pws676qcLpV7dAbw0helJMWFZwn5A8sJT5PebviTfLZ4hKWLM9g+Z4obqql9 XTX2RAE2U2LR8lKRrN967JLy5SnaPyRmoD6CeUqKR8nowK+OrdACUWhAVxyUxxbnu3Jm 2hpye3OkBk7r8P06RfSY34gH+mE+UKT+TNCp2DwndeybPi0aj3O+b46L+S/cj0/b9ACk aVFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774972481; x=1775577281; 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=7TooFR/DlFoJ/jDYD9P1MJwq93UZMJ37xZotM7VxKmI=; b=TLm5TW1cH7jnX0saPmDi8vlgBGUSqlxtM8K4g0m0ddeEraoqjDoBDSiZXDGJEU8afq 7CKDP24i3RIKQIhIUKq1COermCPrOxqfYWmAicsEkLjy9OiJ+WtbnBlU/h8LzMqigQAx D+U0eEANVlLoHPjpKvNzKFterBRlN6I6U5kMKmexTFCSPi2xaRJNv/dcjySmwpr4pLT4 olVAsWLKg9HaRBAFuwGOxJIcat154gEO7/3V3Zx6h1EjW2fzp0pmpO8fqQZlwdWyXa04 UOHBdrQnwQfMvlnU5O/4IphB/ATYtBX5BzHMBynNect51j58nVehUMiJxYBiPUspZ5Hm NeIQ== X-Forwarded-Encrypted: i=1; AJvYcCWgat2sxMA4rkt5e3BdlO2rEdtvPfHUPz9cAJmZ6+DCyYmOG2LYC8lypWrDXFqE2ZsojOwhURC2KV0BqAID@postgresql.org X-Gm-Message-State: AOJu0Yyc3hmE1H7BGhYO7WHOb7FMVBiv+5d+kIRhGfDpbzi5uHfEV4Kr 3U8uiXwuc1bL9lKTU6Kes0eyIlmIouslKt7P9UYfX/W3xkPYvN+S1gtCATAuh0b+8tewEdn+Vln SM3kht8nKLlWOemv0M4iXRk7/CoECjpM= X-Gm-Gg: ATEYQzz7Fr7Hx2RYeZ2/gGzf8Ilydq+aXdQG2rZmVU63Mwf3AyKqsWHlOzJmMRA/I0j BOqVrJalxuV+tH/FyYrnkwFYWTm19nb/qc3KyyhWr14/r/OUcgHdgneZdHBmy9/9AKdhaZcCeQw TWWN7g+qYMRedCDze3Z/9PnWJ/FgSdyb19+3B8aIcntl9XQ22Pcqns7MGEy3vXeLzd+S00Zt3Hg t+yoCyszfRItkStlkAEVW8gHRpYAGfrr71nhAEzgLlZPBD5sWJI/M243doTkzZ0x0xRP+ks6GGv DFXfK1owwrYYrGHXAOkdmCKlw3Yy97BsSKqQ7IJKXsQgvswOn9ThJeSFQxQKr3dDLZ3yWCZO5HL GotrTYb/R X-Received: by 2002:a05:6402:2706:b0:66b:eb1d:b22a with SMTP id 4fb4d7f45d1cf-66db0cf8c93mr11715a12.26.1774972481315; Tue, 31 Mar 2026 08:54:41 -0700 (PDT) MIME-Version: 1.0 References: <2BE661BA-D909-4093-BF78-DB9B0C099337@gmail.com> <77FA04FE-1F84-4DA1-8855-8BBFD8CC889A@gmail.com> In-Reply-To: From: Junwang Zhao Date: Tue, 31 Mar 2026 23:54:29 +0800 X-Gm-Features: AQROBzD0Er6dWfbnqTam0Dq3-vsYL4BCarKc7aNTgGxaFilzqOZfiNBRfTAc4p0 Message-ID: Subject: Re: Eliminating SPI / SQL from some RI triggers - take 3 To: Amit Langote Cc: Chao Li , Haibo Yan , Pavel Stehule , PostgreSQL-development , Tomas Vondra 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 Hi Amit, On Tue, Mar 31, 2026 at 8:15=E2=80=AFPM Amit Langote wrote: > > On Tue, Mar 31, 2026 at 7:57=E2=80=AFPM Junwang Zhao = wrote: > > On Tue, Mar 31, 2026 at 5:17=E2=80=AFPM Amit Langote wrote: > > > On Tue, Mar 31, 2026 at 6:09=E2=80=AFPM Chao Li wrote: > > > > > On Mar 30, 2026, at 19:15, Amit Langote = wrote: > > > > > Kept looking at 0002 and found a couple of things to improve or c= hange > > > > > my thoughts about. I decided to move the permission check from f= ast > > > > > path cache entry creation into ri_FastPathBatchFlush(), alongside= the > > > > > snapshot, so that permission changes between flushes are respecte= d > > > > > rather than checked once at batch start; the check happens for ev= ery > > > > > row in the SPI and non-batched fast path. Also, improved comment= s in > > > > > a few places to mention design decisions better. > > > > > > > > > > 0001 is mostly unchanged from v11 except I updated its commit mes= sage > > > > > to explain why only RI_FKey_check is covered and not the action > > > > > triggers as the topic has come up in previous threads about this > > > > > topic. > > > > > > > > > > Still planning to commit 0001 tomorrow. > > > > > > > > > > -- > > > > > Thanks, Amit Langote > > > > > <= v12-0002-Batch-FK-rows-and-use-SK_SEARCHARRAY-for-fast-pa.patch> > > > > > > > > Hi Amit, > > > > > > > > While reading the recent commits, I saw that 0001 has been pushed a= s 2da86c1ef9b5446e0e22c0b6a5846293e58d98e3. However, I also just noticed a = use-after-free issue in ri_LoadConstraintInfo(). It dereferences conForm af= ter ReleaseSysCache(tup), which is unsafe. I am attaching a tiny patch to f= ix that. > > > > > > Thanks. I noticed that too and pushed the fix an hour ago: > > > > > > https://www.postgresql.org/message-id/E1w7U6V-002H6n-0o%40gemulon.pos= tgresql.org > > > > > > -- > > > Thanks, Amit Langote > > > > prion is happy now, the fix works, thanks. > > Yep, good. > > Because I noticed a use-after-free with prion, I thought to check our > preparedness for CLOBBER_CACHE_ALWAYS and found issues in both the > committed patch (and similar code in 0002): riinfo going stale inside > ri_FastPathCheck() after relation opens and dangling fpmeta pointer > after riinfo invalidation. 0001 fixes those; I'll apply it tomorrow > morning. + if (riinfo->fpmeta =3D=3D NULL) + { + /* Reload to ensure it's valid. */ + riinfo =3D ri_LoadConstraintInfo(riinfo->constraint_id); I was thinking of wrapping the reload in a conditional check like `!riinfo->valid`, since `riinfo` can be valid even when `fpmeta =3D=3D NULL= `. However, `if (riinfo->fpmeta =3D=3D NULL)` should rarely be true, so the unconditional reload is harmless, and the code is cleaner. +1 to the fix. > > 0002 is the rebased batching patch. The change of RI_FastPathEntry from storing riinfo to fk_relid makes sense to me. I'll do another review on 0002 tomorrow. > > -- > Thanks, Amit Langote --=20 Regards Junwang Zhao