| From: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Fix infer_arbiter_index during concurrent index operations |
| Date: | 2025-11-24 16:18:34 |
| Message-ID: | E1vNZGr-001C9L-21@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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(at)gmail(dot)com>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Discussion: https://postgr.es/m/CANtu0ogv+6wqRzPK241jik4U95s1pW3MCZ3rX5ZqbFdUysz7Qw@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/bc32a12e0db2df203a9cb2315461578e08568b9c
Modified Files
--------------
src/backend/commands/indexcmds.c | 3 +
src/backend/executor/execIndexing.c | 8 +
src/backend/executor/execPartition.c | 5 +-
src/backend/executor/nodeModifyTable.c | 2 +
src/backend/optimizer/util/plancat.c | 27 ++-
src/backend/utils/time/snapmgr.c | 2 +
src/test/modules/injection_points/Makefile | 7 +-
.../index-concurrently-upsert-predicate.out | 86 ++++++++
.../expected/index-concurrently-upsert.out | 86 ++++++++
.../expected/reindex-concurrently-upsert.out | 238 +++++++++++++++++++++
src/test/modules/injection_points/meson.build | 7 +
.../specs/index-concurrently-upsert-predicate.spec | 88 ++++++++
.../specs/index-concurrently-upsert.spec | 87 ++++++++
.../specs/reindex-concurrently-upsert.spec | 111 ++++++++++
14 files changed, 749 insertions(+), 8 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nathan Bossart | 2025-11-24 18:36:25 | Re: pgsql: Teach DSM registry to ERROR if attaching to an uninitialized ent |
| Previous Message | Michael Paquier | 2025-11-24 10:34:48 | pgsql: Move isolation test index-killtuples to src/test/modules/index/ |