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

Started by Zhijie Hou1 day ago1 messageshackers
Jump to latest
#1Zhijie Hou
houzhijie22@gmail.com

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

Attachments:

t259940_1
v1-0001-Fix-parallel-build-of-exclusion-constraint-indexe.patchtext/plain; charset=UTF-8; name=v1-0001-Fix-parallel-build-of-exclusion-constraint-indexe.patchDownload+55-6