Make index_concurrently_create_copy more general

Álvaro Herrera <alvherre@kurilemu.de>

Commit: 33bf7318f94ce730563eb5ed95ad6c61d6e6f7a6
Author: Álvaro Herrera <alvherre@kurilemu.de>
Date: 2026-04-04T18:38:26Z
Make index_concurrently_create_copy more general

Also rename it to index_create_copy.  Add a 'boolean concurrent' option,
and make it work for both cases: in concurrent mode, just create the
catalog entries; caller is responsible for the actual building later.
In non-concurrent mode, the index is built right away.

This allows it to be reused for other purposes -- specifically, for
concurrent REPACK.

(With the CONCURRENTLY option, REPACK cannot simply swap the heap file and
rebuild its indexes.  Instead, it needs to build a separate set of
indexes, including their system catalog entries, *before* the actual
swap, to reduce the time AccessExclusiveLock needs to be held for.  This
approach is different from what CREATE INDEX CONCURRENTLY does.)

Per a suggestion from Mihail Nikalayeu.

Author: Antonin Houska <ah@cybertec.at>
Reviewed-by: Mihail Nikalayeu <mihailnikalayeu@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/41104.1754922120@localhost

Files

PathChange+/−
src/backend/catalog/index.c modified +28 −13
src/backend/commands/indexcmds.c modified +5 −4
src/include/catalog/index.h modified +3 −4

Discussion