pgsql: Fix ON CONFLICT with REINDEX CONCURRENTLY and partitions - Mailing list pgsql-committers

From Álvaro Herrera
Subject pgsql: Fix ON CONFLICT with REINDEX CONCURRENTLY and partitions
Date
Msg-id E1vQPuX-002Qy4-2J@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix ON CONFLICT with REINDEX CONCURRENTLY and partitions

When planning queries with ON CONFLICT on partitioned tables, the
indexes to consider as arbiters for each partition are determined based
on those found in the parent table.  However, it's possible for an index
on a partition to be reindexed, and in that case, the auxiliary indexes
created on the partition must be considered as arbiters as well; failing
to do that may result in spurious "duplicate key" errors given
sufficient bad luck.

We fix that in this commit by matching every index that doesn't have a
parent to each initially-determined arbiter index.  Every unparented
matching index is considered an additional arbiter index.

Closely related to the fixes in bc32a12e0db2 and 2bc7e886fc1b, and for
identical reasons, not backpatched (for now) even though it's a
longstanding issue.

Author: Mihail Nikalayeu <mihailnikalayeu@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/CANtu0ojXmqjmEzp-=aJSxjsdE76iAsRgHBoK0QtYHimb_mEfsg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/90eae926abbbcedbbea2ad5302722185e8652dca

Modified Files
--------------
src/backend/executor/execPartition.c               | 170 +++++++++++++--
src/test/modules/injection_points/Makefile         |   3 +-
.../reindex-concurrently-upsert-partitioned.out    | 238 +++++++++++++++++++++
src/test/modules/injection_points/meson.build      |   3 +-
.../reindex-concurrently-upsert-partitioned.spec   | 113 ++++++++++
5 files changed, 506 insertions(+), 21 deletions(-)


pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: pgsql: Remove useless casting to same type
Next
From: Álvaro Herrera
Date:
Subject: pgsql: Avoid use of NOTICE to wait for snapshot invalidation