]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add comment explaining fire_triggers=false in ri_PerformCheck()
authorAmit Langote <amitlan@postgresql.org>
Mon, 30 Mar 2026 01:10:17 +0000 (10:10 +0900)
committerAmit Langote <amitlan@postgresql.org>
Mon, 30 Mar 2026 01:10:17 +0000 (10:10 +0900)
The reason for passing fire_triggers=false to SPI_execute_snapshot()
in ri_PerformCheck() was not documented, making it unclear why it was
done that way.  Add a comment explaining that it ensures AFTER triggers
on rows modified by the RI action are queued in the outer query's
after-trigger context and fire only after all RI updates on the same
row are complete.

Author: Yugo Nagata <nagata@sraoss.co.jp>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Surya Poondla <suryapoondla4@gmail.com>
Discussion: https://postgr.es/m/20250331212648.ad4ab804559001d7f0788741@sraoss.co.jp

src/backend/utils/adt/ri_triggers.c

index d22b8ef7f3c10ebb5511ea5e5c0b5aed8c67be51..6230a2ea9adfe3635ef165368739e82da551cee1 100644 (file)
@@ -2582,7 +2582,13 @@ ri_PerformCheck(const RI_ConstraintInfo *riinfo,
                                                   save_sec_context | SECURITY_LOCAL_USERID_CHANGE |
                                                   SECURITY_NOFORCE_RLS);
 
-       /* Finally we can run the query. */
+       /*
+        * Finally we can run the query.
+        *
+        * Set fire_triggers to false to ensure that AFTER triggers are queued in
+        * the outer query's after-trigger context and fire after all RI updates
+        * on the same row are complete, rather than immediately.
+        */
        spi_result = SPI_execute_snapshot(qplan,
                                                                          vals, nulls,
                                                                          test_snapshot, crosscheck_snapshot,