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 1w7WnM-005PV2-1w for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2026 10:58:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7WnL-009hLA-0L for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2026 10:58:03 +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 1w7WnK-009hL0-2G for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2026 10:58:03 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w7WnJ-00000001xJc-1Swm for pgsql-hackers@postgresql.org; Tue, 31 Mar 2026 10:58:02 +0000 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-66beb35caafso3601881a12.2 for ; Tue, 31 Mar 2026 03:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774954679; cv=none; d=google.com; s=arc-20240605; b=g6W51e+IxrIWApBMiXlVNgYEyznV6X4Hqf/WT9abJxJIW8yF6l7ApCBEEo7N07b9d7 NCcdVdFSliO2ALVG5fPJQMGEmHycOfyVg1tvJUCouugwxg7DFaVpxUDNGsAxodK/1Q8C pyi+g8qXdteagLnpWBX/kAH/1v4qw1Tn0dbNV4Km3K9xXOgPms/PXUBv7pdAftqm3SvJ L/5LGtdMhpgBRVEkHMWp1h/fJGSJEo3Bzq6oJl3idps+Vsue4ZPiLaKvW6enaZcLGeB3 Q88UWfmXAQNhLWIybJUbGoIKTHDIV/3JPKakTxEmt/7IE22opxm/9GcZhmtdmmN+tnxz HJkw== 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=0bsXAhbCGvRTkvSI0RmRltypRKhh7Obr/Grxp95A6Mw=; fh=Dd5k6p9+E9HHjAAAACVLEL618ttra6D4UV/Cohwoso8=; b=T889Q4z5ERf/+z+ypGbokV2SsRZCTxipmrU7L1LI6KsULsyzp37ickKZZ8Km4ZKH3D /ToTvqUDFX6CVCHg5BiWHU2QJgu9j8uG/FSnVDXBZmnCa2HFNSNXXHDDiXHdw0EQ+QW2 Y6N2OmvDNz+aGPnc1ARG/fM1lH0m1JHxnYO7/88+MUmDPrSjwymnheptRI47PqmQAKdS bIZ70DwWsAXkkMFXExPy/yUfyVZrVxAg6pmo4xK4wOJfOgD1xg2VAJMvUg7VGe5+lHvu uEhl0k+YPVzrV3SB9Y7BJqBvRkKG6ALo78B5rtK7eAZczkCU5QBFMAUxl36hn/ifZ+js Wj9g==; 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=1774954679; x=1775559479; 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=0bsXAhbCGvRTkvSI0RmRltypRKhh7Obr/Grxp95A6Mw=; b=OfV7kfbnfx2Va+JU4IBrOYY0gh1RLw1dl6WidtIJZGH4lfrepHUKRlC7JzQqazSaPt iNoT3lknQRZeobaHTI0NYE8do1yVliTZJFl5PEJ1x9ey86LOZI+ZeV/QbMiBz3Y922Ik xwZNlBrE7lQ7BJj8uqbydCTtbFNoAdwip24O/eehloixPfgVduP6bhi33U8JQQTfWHxY zlMLVx+D/CF6Z6DWUpsSsIEfTkYxvY48yzyTnYu0uVihcDbV+nu90ZK1dqtLxKgguX0/ 5m2xUoB75tru2XUhaG4m76GxiUdShmB3ByFTGDBf92vRpFSKWlpRgV5/XaIvjh+LuGlp q0vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774954679; x=1775559479; 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=0bsXAhbCGvRTkvSI0RmRltypRKhh7Obr/Grxp95A6Mw=; b=EODEkDenLn3FuHwMXLDQxZrLKFWGELOwper9d6NpahYHWEkii/CtuWAgpNnwmERtU/ +VW3AuXanmLfK0gIAjYbBi8yeNShIJni/6T2ANVpFuK5FEMcJlrvQqn5XBN57ZQMKLOD KjheNzmtQnsBZCTmUdR0CeIo2Qp5taZbdkGajP/27KRLTakU764+bmBQ/3WPfUJXhhE6 fPX96EyxlGD3oF3DVC9dAXOCs+d3f8P75h/xiOTEsxyMeaxMeU8JoDXYDdPR5CTMyQjC sG2niJFrA9SBDQkruL+FyWsZAHoIDRwoKLd4a7OGMuvtw4vjN85CGFFrSFNOQ1AZfTvo qTIw== X-Forwarded-Encrypted: i=1; AJvYcCUtaVT+fF2RwvSpHd7cDYa6BFcWHVj5weII3EozZRvEelewiEn367t2zKF/xavB/xuvKraX6Z/Cc+mM7EZP@postgresql.org X-Gm-Message-State: AOJu0Yx8zvGk6Gg6UcudhCfEfK3hG9uXeFYe/NUTuzZzS9STYpMRbPGS MNYSMtumB0MOR+gHLVTYeVxJ6FasM0D/eczLqo7IM5aHHMw16L6SisWwfd0jSAKkna2CWo7Sgn+ UAOzP6eZODMonWL/V2vzbxEcTOXZCCbM= X-Gm-Gg: ATEYQzwXwJDxrQpwjQkHFBiL+NgaKelN7DjiwEn3AVFDAD/hTQuQFSL7eL00gyavPzc 532NyN6kJwa+T5SAZN99wWEpq89BQHgsY+Zclu4EZXhy8ru6r7Yoqfz1WNKhM6G1fitdryPMXaC efpCT/35ywwUyv8whZY2dXkfp55Qb4LtwRjAUMNkUpRxqA5MPyXF6O5ocXQMCu60aQUfb9po0to UEMvUxF3X69bmX5Ge8tshk+Mz/9WZLuWLGm8F/8Cgk8JCjdgAUZ+mtHD9hg5zTnCwAq9qcuDH2U MQ+ZlKLdT/BGQ59mA+YZyrmevugCvh47Gr+W9jMw8n4jT9+7wDXwtwXO7pqMBe7VZziq3g== X-Received: by 2002:a05:6402:4618:b0:669:d766:6c93 with SMTP id 4fb4d7f45d1cf-66b28c6ada7mr7377958a12.16.1774954678467; Tue, 31 Mar 2026 03:57:58 -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 18:57:46 +0800 X-Gm-Features: AQROBzCjCf9C0aC6xgR7odo7itlX2e4Lk6V7CNHuZSRx_05KowWjjB7brnOeaTs 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 On Tue, Mar 31, 2026 at 5:17=E2=80=AFPM Amit Langote wrote: > > Hi, > > On Tue, Mar 31, 2026 at 6:09=E2=80=AFPM Chao Li = wrote: > > > On Mar 30, 2026, at 19:15, Amit Langote wro= te: > > > > > > On Mon, Mar 30, 2026 at 1:55=E2=80=AFPM Amit Langote wrote: > > >> Junwang pointed out off-list that FK tuples added to > > >> RI_FastPathEntry.batch[] were being copied into TopTransactionContex= t > > >> rather than flush_cxt, so they would accumulate until the batch was > > >> exhausted rather than being reclaimed per flush. Fixed in > > >> ri_FastPathBatchAdd() in 0002. > > >> > > >> Also added a couple of comments in trigger.c that were missing: an > > >> Assert and explanation in RegisterAfterTriggerBatchCallback() > > >> clarifying the query_depth >=3D 0 precondition, a comment at the > > >> AfterTriggerEndQuery call site explaining why > > >> FireAfterTriggerBatchCallbacks() must precede the query_depth > > >> decrement and AfterTriggerFreeQuery, and brief intent comments at th= e > > >> AfterTriggerFireDeferred and AfterTriggerSetState call sites. > > >> > > >> Plan is to commit 0001 tomorrow barring objections and let it sit fo= r > > >> a bit before committing 0002. Feedback on 0002, particularly on the > > >> AfterTriggerBatchCallback mechanism in trigger.c, welcome in the > > >> meantime. > > > > > > Kept looking at 0002 and found a couple of things to improve or chang= e > > > my thoughts about. I decided to move the permission check from fast > > > path cache entry creation into ri_FastPathBatchFlush(), alongside the > > > snapshot, so that permission changes between flushes are respected > > > rather than checked once at batch start; the check happens for every > > > row in the SPI and non-batched fast path. Also, improved comments in > > > a few places to mention design decisions better. > > > > > > 0001 is mostly unchanged from v11 except I updated its commit message > > > 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 > > > > > > > Hi Amit, > > > > While reading the recent commits, I saw that 0001 has been pushed as 2d= a86c1ef9b5446e0e22c0b6a5846293e58d98e3. However, I also just noticed a use-= after-free issue in ri_LoadConstraintInfo(). It dereferences conForm after = ReleaseSysCache(tup), which is unsafe. I am attaching a tiny patch to fix t= hat. > > Thanks. I noticed that too and pushed the fix an hour ago: > > https://www.postgresql.org/message-id/E1w7U6V-002H6n-0o%40gemulon.postgre= sql.org > > -- > Thanks, Amit Langote prion is happy now, the fix works, thanks. --=20 Regards Junwang Zhao