Add support for partitioned tables and indexes in REINDEX
authorMichael Paquier <michael@paquier.xyz>
Tue, 8 Sep 2020 01:09:22 +0000 (10:09 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 8 Sep 2020 01:09:22 +0000 (10:09 +0900)
commita6642b3ae060976b42830b7dc8f29ec190ab05e4
tree1a95529f5569ac9d87b4785a4e2b00b0f04f78df
parenta547e6867527ca16628a3fb1cf3ef6f785210a31
Add support for partitioned tables and indexes in REINDEX

Until now, REINDEX was not able to work with partitioned tables and
indexes, forcing users to reindex partitions one by one.  This extends
REINDEX INDEX and REINDEX TABLE so as they can accept a partitioned
index and table in input, respectively, to reindex all the partitions
assigned to them with physical storage (foreign tables, partitioned
tables and indexes are then discarded).

This shares some logic with schema and database REINDEX as each
partition gets processed in its own transaction after building a list of
relations to work on.  This choice has the advantage to minimize the
number of invalid indexes to one partition with REINDEX CONCURRENTLY in
the event a cancellation or failure in-flight, as the only indexes
handled at once in a single REINDEX CONCURRENTLY loop are the ones from
the partition being working on.

Isolation tests are added to emulate some cases I bumped into while
developing this feature, particularly with the concurrent drop of a
leaf partition reindexed.  However, this is rather limited as LOCK would
cause REINDEX to block in the first transaction building the list of
partitions.

Per its multi-transaction nature, this new flavor cannot run in a
transaction block, similarly to REINDEX SCHEMA, SYSTEM and DATABASE.

Author: Justin Pryzby, Michael Paquier
Reviewed-by: Anastasia Lubennikova
Discussion: https://postgr.es/m/db12e897-73ff-467e-94cb-4af03705435f.adger.lj@alibaba-inc.com
13 files changed:
contrib/postgres_fdw/expected/postgres_fdw.out
contrib/postgres_fdw/sql/postgres_fdw.sql
doc/src/sgml/ref/reindex.sgml
src/backend/catalog/index.c
src/backend/commands/indexcmds.c
src/backend/tcop/utility.c
src/include/commands/defrem.h
src/test/isolation/expected/reindex-partitions.out [new file with mode: 0644]
src/test/isolation/isolation_schedule
src/test/isolation/specs/reindex-partitions.spec [new file with mode: 0644]
src/test/regress/expected/create_index.out
src/test/regress/sql/create_index.sql
src/tools/pgindent/typedefs.list