agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Amit Langote <amitlan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix deferred FK check batching introduced by commit b7b27eb41a5
Date: Tue, 07 Apr 2026 01:48:40 +0000
Message-ID: <E1w9vYV-003JwP-1z@gemulon.postgresql.org> (raw)
Fix deferred FK check batching introduced by commit b7b27eb41a5
That commit introduced AfterTriggerIsActive() to detect whether
we are inside the after-trigger firing machinery, so that RI trigger
functions can take the batched fast path. It was implemented using
query_depth >= 0, which correctly identified immediate trigger firing
but missed the deferred case where query_depth is -1 at COMMIT via
AfterTriggerFireDeferred(). This caused deferred FK checks to fall
back to the per-row fast path instead of the batched path.
The correct check is whether we are inside an after-trigger firing
loop specifically. Introduce afterTriggerFiringDepth, a counter
incremented around the trigger-firing loops in AfterTriggerEndQuery,
AfterTriggerFireDeferred, and AfterTriggerSetState, and decremented
after FireAfterTriggerBatchCallbacks() returns. AfterTriggerIsActive()
now returns afterTriggerFiringDepth > 0.
Reported-by: Chao Li <li.evan.chao@gmail.com>
Author: Chao Li <li.evan.chao@gmail.com>
Co-authored-by: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/C2133B47-79CD-40FF-B088-02D20D654806@gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/5c54c3ed1b934a35a8e9eacff679699ccb3a5070
Modified Files
--------------
src/backend/commands/trigger.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
Message-ID: <E1w9vYV-003JwP-1z@gemulon.postgresql.org>
Permalink: ../E1w9vYV-003JwP-1z@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1w9vYV-003JwP-1z@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: amitlan@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Fix deferred FK check batching introduced by commit b7b27eb41a5
In-Reply-To: <E1w9vYV-003JwP-1z@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox