postgresql/src
Álvaro Herrera bc32a12e0d
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
2025-11-24 17:17:29 +01:00
..
backend Fix infer_arbiter_index during concurrent index operations 2025-11-24 17:17:29 +01:00
bin psql: Improve tab-completion for PREPARE. 2025-11-23 23:03:53 +09:00
common Document that pg_getaddrinfo_all does not accept null hints 2025-11-13 16:35:07 +01:00
fe_utils Add \pset options for boolean value display 2025-11-03 17:40:39 +01:00
include C11 alignas instead of unions -- extended alignments 2025-11-24 07:39:37 +01:00
interfaces Fix typo 2025-11-18 19:31:23 +01:00
makefiles Remove traces of support for Sun Studio compiler 2025-09-12 07:39:05 +02:00
pl Avoid memory leak in validation of a PL/Python trigger function. 2025-10-23 14:23:26 -04:00
port Handle EPERM in pg_numa_init 2025-11-20 13:26:49 +01:00
template Remove traces of support for Sun Studio compiler 2025-09-12 07:39:05 +02:00
test Fix infer_arbiter_index during concurrent index operations 2025-11-24 17:17:29 +01:00
timezone Update timezone to C99 2025-11-21 13:07:40 +01:00
tools pg_buffercache: Add pg_buffercache_os_pages 2025-11-24 14:29:15 +09:00
tutorial Fix compile of src/tutorial/funcs.c 2025-10-07 10:45:57 +02:00
.gitignore
DEVELOPERS
Makefile
Makefile.global.in Remove traces of support for Sun Studio compiler 2025-09-12 07:39:05 +02:00
Makefile.shlib Use exported symbols list on macOS for loadable modules as well 2025-06-10 07:04:43 +02:00
meson.build Update copyright for 2025 2025-01-01 11:21:55 -05:00
nls-global.mk Fix update-po for the PGXS case 2025-10-16 20:21:05 +02:00