pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Álvaro Herrera <alvherre@kurilemu.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix ON CONFLICT with REINDEX CONCURRENTLY and partitions
Date: Tue, 02 Dec 2025 12:55:18 +0000
Message-ID: <E1vQPuX-002Qy4-2J@gemulon.postgresql.org> (raw)

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



Message-ID: <E1vQPuX-002Qy4-2J@gemulon.postgresql.org>
Permalink:  ../E1vQPuX-002Qy4-2J@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1vQPuX-002Qy4-2J@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: alvherre@kurilemu.de, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix ON CONFLICT with REINDEX CONCURRENTLY and partitions
  In-Reply-To: <E1vQPuX-002Qy4-2J@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox