pgsql: Fix infer_arbiter_index during concurrent index operations - Mailing list pgsql-committers

From Álvaro Herrera
Subject pgsql: Fix infer_arbiter_index during concurrent index operations
Date
Msg-id E1vNZGr-001C9L-21@gemulon.postgresql.org
Whole thread Raw
List 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@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

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(-)


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: Move isolation test index-killtuples to src/test/modules/index/
Next
From: Jacob Champion
Date:
Subject: pgsql: Add pg_add_size_overflow() and friends