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 1w7VE9-005NkF-1H for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2026 09:17:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7VE7-0097pv-2W for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2026 09:17:36 +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 1w7VE7-0097pn-1E for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2026 09:17:35 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w7VE6-00000001wYo-08Ma for pgsql-hackers@postgresql.org; Tue, 31 Mar 2026 09:17:34 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-35691a231a7so3294290a91.3 for ; Tue, 31 Mar 2026 02:17:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774948653; cv=none; d=google.com; s=arc-20240605; b=Kjq0Gbe0vxH7+f5DM+A3m28q7vmcQlUygtdtAWEUNSufrDneDvifkLJdjNNBT7gJOF Oliyj7N7Trapeltr0d1nZ6KZc9Nh6npsOk1kBEprvKDAuOdF61gbJWaPAC5m14yYBATh O3bGqX4IMhEqG+1dOzg17XZH0ykWX3MNpmjrLcYKvQFifs82RF8ETaOGd80QM5wak+v6 vfSC0gZDqBbSu/L7b6q/GwRWTBXovBKkh/BgYpQ5w4QoVJnXMuPjWKzcuclkt2TcEWRy Q1blpWzTAJ+ylgAJVsmKTo/kJf95Moto+vxLHSmBLkY5u1AbY3uXiWnCHxCQQp2FUOqg Ihcw== 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=JpDXMcenGQLVunMevYgCO8W8cLS8ydCBhfBNrLgv3q0=; fh=tChMkO8rNwYh/dVRewmZFSTV49c/+SaI/2TVtvDrnOc=; b=BkRApnCLQAdtMtpPDbO/ngqX8MGS966mm93RdWEv1DSbiIF6bz5WvHf/8ftDQZPhpl z+Igg6pBTFToIdRLUZHHN9OD1f9qw0ubdYGjSO0iIEXGeU93Agq6WdanZn3lihXyGHDz 78cm1mdoC2GqiE6xL7N1X3oWnJdWzXLtC1b6VjGR4jHG8WDZb0IWBFY44QacPu7D9fmJ dLtIZ7t1pRHooKnLgpQ0VMihrjCR7uF4UG2+2ptGkixZOqRce7v+KcT/wpZ6cjG4L7eU rbVrK8+br/R5oQ6uV5jaZexRuQ1cEKekW3L3YP2n9r+aAkzZ5tifqayeTnoPM+DTMXTD COcw==; 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=1774948653; x=1775553453; 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=JpDXMcenGQLVunMevYgCO8W8cLS8ydCBhfBNrLgv3q0=; b=PCWb+18I2IQjA8oH+vz1/MYr20zaHJvdTAtbyWUBFosHo+BJQrC9vNR0LzpNig4laJ hGjG4oDspKkSIweUpKh+ovshowqF8xpMMKwBh8wRVNSeK0euTIWJpZfiPjhoLGliN8Dl 9pPHKjba/hjahIKX5Dhhx/Gje6BnkYy/Y6uRFikz2ZNo7KbucRpqI/w9jqXmOhwOxBsa +8cQpaHXoPwfBUV++0ZWQK8nfkSj7giWhDk5qUI4GDVVMDiYEthtdTsZFYP6Lm84JuuG ozJIGv/AupBS3twzgJ9OExIio+c1okm2+2K3GZSy6LWJsPUxmEF+ON3CmxOQtuzG9ER+ IKbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774948653; x=1775553453; 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=JpDXMcenGQLVunMevYgCO8W8cLS8ydCBhfBNrLgv3q0=; b=SJW2vJYwsebCDR6h9wHPRXg+umTgE16uhkK5qobZUi2U2bJYIrt8lck7Fmu7/SR7rg BjCrsoPXFHlq7W9curoraeIdiYcfSw3G3rqM7uYM6caGE4MAdah+iBs2ZBq4+HLcyoqK zoZ/ddOikTCmY37MCy2cqVTalqGXDYHbtedFFhBgAQ/106DUeBBiw7zgJmNi5EwflzEC Mfqm4D9hvMUtxr1UbenOmWDlo8mfAo4hEhxVSY4QeFjsc8ivoVIrZvr0a+Ens+x3x9dW awnANQIvOue+9Bz2JMOxZJzcR5YHl9pjWJ+ZfgKFI8lBuy/p76PtQ35UESsQItRGs3Os Smsg== X-Forwarded-Encrypted: i=1; AJvYcCVmu2hRztfzE8Vx2wb89s1JDjCbrtUl4s4UXzTgNoQa+9MqYkyJIXUqpFISg+wwSxQ1N5sDKL8tijG2HBy+@postgresql.org X-Gm-Message-State: AOJu0YykLe1iUwpzNifsslzQpEQWlUqLkOQGdMgaFqwusWUiAoZvJjK4 M0M8/7ZTy2Tq2AhKaLSJllfY7RwzG5MjmWb+bUoeIGPB0eEYeBxn33liubjPoPGD8Qlbiu15N8A H1qvjrmla2H0IJYe1K5c3aC50rqzW/N3OLPhB X-Gm-Gg: ATEYQzw3mN7fSuK1zhp3PHHcK20N71/5jzO+k7OFAHc1yCuGgMr5VAYW7vMx6H/h7Ou 0S9Z++uVCTgZRVFFXoOtiWosTCmX7E8B/qBBPSL7MWXER7UAhfk+53BWbCglBinKEDyBgeZnryX fTlZExohLYxttlfzZFb7JllzTXiEHsxkrCJQBLJ8zRJXcMBnKdIYxa6m+LCG1Rk3/JTrnmZIYI3 CCqco3vOBJnq8ZuuFF3vzgyyRwIqZEoNy62Ia3GzpZ7QtSbtTVNjmZIxCvhKwfHHKbzJRBCQNKk okI9iVnmp/mc0izxuN4= X-Received: by 2002:a17:90b:2882:b0:35a:1762:92ed with SMTP id 98e67ed59e1d1-35c30093e94mr14682156a91.24.1774948653132; Tue, 31 Mar 2026 02:17:33 -0700 (PDT) MIME-Version: 1.0 References: <2BE661BA-D909-4093-BF78-DB9B0C099337@gmail.com> <77FA04FE-1F84-4DA1-8855-8BBFD8CC889A@gmail.com> In-Reply-To: <77FA04FE-1F84-4DA1-8855-8BBFD8CC889A@gmail.com> From: Amit Langote Date: Tue, 31 Mar 2026 18:17:16 +0900 X-Gm-Features: AQROBzCzix2uoynoXw1q73C7GKel_e7L7-WBv6ylijVypFoG2ytVUOiJsDLiG_4 Message-ID: Subject: Re: Eliminating SPI / SQL from some RI triggers - take 3 To: Chao Li Cc: Junwang Zhao , 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, On Tue, Mar 31, 2026 at 6:09=E2=80=AFPM Chao Li wr= ote: > > On Mar 30, 2026, at 19:15, Amit Langote wrote= : > > > > 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 TopTransactionContext > >> 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 the > >> AfterTriggerFireDeferred and AfterTriggerSetState call sites. > >> > >> Plan is to commit 0001 tomorrow barring objections and let it sit for > >> 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 change > > 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 2da8= 6c1ef9b5446e0e22c0b6a5846293e58d98e3. However, I also just noticed a use-af= ter-free issue in ri_LoadConstraintInfo(). It dereferences conForm after Re= leaseSysCache(tup), which is unsafe. I am attaching a tiny patch to fix tha= t. Thanks. I noticed that too and pushed the fix an hour ago: https://www.postgresql.org/message-id/E1w7U6V-002H6n-0o%40gemulon.postgresq= l.org --=20 Thanks, Amit Langote