Fix ON CONFLICT with REINDEX CONCURRENTLY and partitions
authorÁlvaro Herrera <[email protected]>
Tue, 2 Dec 2025 12:51:19 +0000 (13:51 +0100)
committerÁlvaro Herrera <[email protected]>
Tue, 2 Dec 2025 12:51:53 +0000 (13:51 +0100)
commit90eae926abbbcedbbea2ad5302722185e8652dca
tree74943ac23b6ed6dfff725106047adb1b26e18654
parent4f941d432b42eccd99ba0d22e3a59c073ac2406a
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 <[email protected]>
Reviewed-by: Álvaro Herrera <[email protected]>
Discussion: https://postgr.es/m/CANtu0ojXmqjmEzp-=aJSxjsdE76iAsRgHBoK0QtYHimb_mEfsg@mail.gmail.com
src/backend/executor/execPartition.c
src/test/modules/injection_points/Makefile
src/test/modules/injection_points/expected/reindex-concurrently-upsert-partitioned.out [new file with mode: 0644]
src/test/modules/injection_points/meson.build
src/test/modules/injection_points/specs/reindex-concurrently-upsert-partitioned.spec [new file with mode: 0644]