REPACK (CONCURRENTLY) fails during parallel build of exclusion constraint indexes

From: Zhijie Hou <houzhijie22(at)gmail(dot)com>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Subject: REPACK (CONCURRENTLY) fails during parallel build of exclusion constraint indexes
Date: 2026-11-27 16:08:10
Message-ID: f5b43b60-1f33-420c-821d-9b3ab83ce28a@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

While testing REPACK (CONCURRENTLY), I noticed that it fails when
rebuilding an exclusion constraint index with parallel workers:

CREATE TABLE rpk_excl (
id int PRIMARY KEY,
a int,
EXCLUDE USING btree (a WITH =)
) WITH (parallel_workers = 2);
INSERT INTO rpk_excl VALUES (1, 10), (2, 20);
REPACK (CONCURRENTLY) rpk_excl;
ERROR: exclusion constraint record missing for rel
rpk_excl_a_excl_repacknew

In build_new_indexes(), index_create_copy() is called without
INDEX_CREATE_SKIP_BUILD before copy_index_constraints(). As a result,
index_create() inserts the pg_index entry for the new index with
indisexclusion set to true, advances the command counter, and
immediately runs index_build() before copy_index_constraints() creates
the corresponding pg_constraint entry on the transient table. When the
parallel index build workers open the new index and call
BuildIndexInfo(), RelationGetExclusionInfo() cannot find the
pg_constraint entry on the transient table and raises the error above.

The attached patch fixes this by passing INDEX_CREATE_SKIP_BUILD to
index_create_copy(), copying the index constraints onto the transient
table first, and then invoking index_build(). This issue affects master
and REL_19_STABLE.
--
Best Regards,
Zhijie Hou

Attachment Content-Type Size
v1-0001-Fix-parallel-build-of-exclusion-constraint-indexe.patch text/plain 5.6 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Zsolt Parragi 2026-11-27 16:23:19 Re: What is up on BF member kestrel?
Previous Message Fabrice Chapuis 2026-11-27 16:06:00 Re: unidirectional logical replication logging issue