pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Remove batching from RI fast-path checks
2+ messages / 1 participants
[nested] [flat]

* pgsql: Remove batching from RI fast-path checks
@ 2026-09-10 05:46 Amit Langote <amitlan@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Amit Langote @ 2026-09-10 05:46 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Remove batching from RI fast-path checks

Commit b7b27eb41a5 added batching to the direct-index fast path for
foreign key checks introduced by 2da86c1ef9b. Instead of probing the
referenced index once per row, it accumulated referencing rows and
checked them in groups, using SK_SEARCHARRAY for single-column foreign
keys.

The batching requires state to survive across trigger invocations and
to be flushed at the end of each trigger-firing cycle. Follow-up work
has had to define how that state interacts with nested trigger firing,
subtransactions, deferred constraints, and SET CONSTRAINTS.

Failure to handle one of those cases can leave a buffered check
unperformed, allowing a transaction to commit a permanent foreign key
violation without reporting an error. With PostgreSQL 19 close to
release, there is not enough time to gain confidence that all relevant
trigger and transaction states have been covered.

Remove the batching and its after-trigger callback infrastructure,
including the per-batch RI cache and associated subtransaction cleanup.
Restore the early exit in AfterTriggerFireDeferred(), since batch
callbacks can no longer queue additional deferred triggers after
afterTriggerInvokeEvents() returns.

Remove tests that exercise only the batching implementation and its
callback and cache lifetime machinery. Retain tests that continue to
exercise the underlying per-row fast path, including validation,
scan-key construction, cross-type rechecks, deferred checks, and
metadata invalidation.

Keep the underlying per-row fast path. It performs each check
synchronously and retains no pending checks across trigger invocations.
Also retain the fixes made to the per-row probe path, including support
for domain-typed referencing columns, restriction to btree referenced
indexes, concurrent index replacement, metadata invalidation, and
nullable referenced keys.

This removal applies only to REL_19_STABLE.

Discussion: https://postgr.es/m/CA+HiwqEDcCSDoYTtoXH4Ta_BpGN+revMZSLLj6GRz2_5ybwE1g@mail.gmail.com

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/25649d6e791c2d803fff0ce8b69ed968028a5edc

Modified Files
--------------
.git-blame-ignore-revs                             |   3 -
doc/src/sgml/release-19.sgml                       |   4 -
src/backend/access/transam/xact.c                  |   2 -
src/backend/commands/trigger.c                     | 206 +----
src/backend/utils/adt/ri_triggers.c                | 937 +--------------------
src/include/commands/trigger.h                     |  24 -
src/test/isolation/isolation_schedule              |   2 +-
.../specs/ri_fastpath_reindex.spec                 |  12 +-
src/test/regress/expected/foreign_key.out          | 347 +-------
src/test/regress/expected/triggers.out             |  24 -
src/test/regress/sql/foreign_key.sql               | 305 +------
src/test/regress/sql/triggers.sql                  |  23 -
src/tools/pgindent/typedefs.list                   |   4 -
13 files changed, 128 insertions(+), 1765 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Remove batching from RI fast-path checks
@ 2026-10-03 02:46 Amit Langote <amitlan@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Amit Langote @ 2026-10-03 02:46 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Remove batching from RI fast-path checks

This removes the buffering of FK rows for batched PK index probes,
along with the after-trigger callback infrastructure used only by
batching.  The per-row fast path, which probes the PK index directly
instead of going through SPI, remains.  This is a cherry-pick of
commit 25649d6e791c2, which made the same change in REL_19_STABLE,
adjusted for some drift between the branches.

I (amitlan) initially thought we could keep improving the batching
path on master by fixing its remaining bugs and other issues as
they were found.  However, we are still finding cases where delaying
checks to accumulate a batch changes their results, such as when other
AFTER ROW triggers modify the referenced table.  Individual cases can
be addressed, but new ones keep turning up, which makes it hard to be
confident that fixing the known ones will be enough.  It seems better
to rip batching out and reconsider how to introduce it, or at least
its useful pieces, while preserving the semantics of per-row checks.

Discussion: https://postgr.es/m/CA+HiwqFx4cjFtC3akr1DW-cPYw+B-EkCSffZPrkpTef8PNS6qA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/425daf545d9146e008220ae0b21415982220cd3f

Modified Files
--------------
src/backend/access/transam/xact.c                  |   2 -
src/backend/commands/trigger.c                     | 206 +----
src/backend/utils/adt/ri_triggers.c                | 979 +--------------------
src/include/commands/trigger.h                     |  24 -
src/test/isolation/isolation_schedule              |   2 +-
.../specs/ri_fastpath_reindex.spec                 |  12 +-
src/test/regress/expected/foreign_key.out          | 347 +-------
src/test/regress/expected/triggers.out             |  24 -
src/test/regress/sql/foreign_key.sql               | 305 +------
src/test/regress/sql/triggers.sql                  |  23 -
src/tools/pgindent/typedefs.list                   |   4 -
11 files changed, 131 insertions(+), 1797 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-10-03 02:46 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-10 05:46 pgsql: Remove batching from RI fast-path checks Amit Langote <amitlan@postgresql.org>
2026-10-03 02:46 pgsql: Remove batching from RI fast-path checks Amit Langote <amitlan@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox