pgsql: Fix ON CONFLICT with REINDEX CONCURRENTLY and partitions

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix ON CONFLICT with REINDEX CONCURRENTLY and partitions
Date: 2025-12-02 12:55:18
Message-ID: E1vQPuX-002Qy4-2J@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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(at)gmail(dot)com>
Reviewed-by: Álvaro Herrera <alvherre(at)kurilemu(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Álvaro Herrera 2025-12-02 15:44:52 pgsql: Avoid use of NOTICE to wait for snapshot invalidation
Previous Message Peter Eisentraut 2025-12-02 09:24:21 pgsql: Remove useless casting to same type