]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix infer_arbiter_index during concurrent index operations
authorÁlvaro Herrera <alvherre@kurilemu.de>
Mon, 24 Nov 2025 16:03:10 +0000 (17:03 +0100)
committerÁlvaro Herrera <alvherre@kurilemu.de>
Mon, 24 Nov 2025 16:17:29 +0000 (17:17 +0100)
commitbc32a12e0db2df203a9cb2315461578e08568b9c
tree6f6cf72fe2ce9a87d9ee163788b5813f8c4460ad
parente429c3cecb4ac55d997acea0f76c5f06d6cb0ab3
Fix infer_arbiter_index during concurrent index operations

Previously, we would only consider indexes marked indisvalid as usable
for INSERT ON CONFLICT.  But that's problematic during CREATE INDEX
CONCURRENTLY and REINDEX CONCURRENTLY, because concurrent transactions
would end up with inconsistents lists of inferred indexes, leading to
deadlocks and spurious errors about unique key violations (because two
transactions are operating on different indexes for the speculative
insertion tokens).  Change this function to return indexes even if
invalid.  This fixes the spurious errors and deadlocks.

Because such indexes might not be complete, we still need uniqueness to
be verified in a different way.  We do that by requiring that at least
one index marked valid is part of the set of indexes returned.  It is
that index that is going to help ensure that the inserted tuple is
indeed unique.

This does not fix similar problems occurring with partitioned tables or
with named constraints.  These problems will be fixed in follow-up
commits.

We have no user report of this problem, even though it exists in all
branches.  Because of that and given that the fix is somewhat tricky, I
decided not to backpatch for now.

Author: Mihail Nikalayeu <mihailnikalayeu@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/CANtu0ogv+6wqRzPK241jik4U95s1pW3MCZ3rX5ZqbFdUysz7Qw@mail.gmail.com
14 files changed:
src/backend/commands/indexcmds.c
src/backend/executor/execIndexing.c
src/backend/executor/execPartition.c
src/backend/executor/nodeModifyTable.c
src/backend/optimizer/util/plancat.c
src/backend/utils/time/snapmgr.c
src/test/modules/injection_points/Makefile
src/test/modules/injection_points/expected/index-concurrently-upsert-predicate.out [new file with mode: 0644]
src/test/modules/injection_points/expected/index-concurrently-upsert.out [new file with mode: 0644]
src/test/modules/injection_points/expected/reindex-concurrently-upsert.out [new file with mode: 0644]
src/test/modules/injection_points/meson.build
src/test/modules/injection_points/specs/index-concurrently-upsert-predicate.spec [new file with mode: 0644]
src/test/modules/injection_points/specs/index-concurrently-upsert.spec [new file with mode: 0644]
src/test/modules/injection_points/specs/reindex-concurrently-upsert.spec [new file with mode: 0644]