From 855344f709a02907a81ccbe950cd99864b1d2030 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Sat, 29 Feb 2020 10:38:18 -0600 Subject: [PATCH v4 2/2] CREATE INDEX CONCURRENTLY to preserve CLUSTER.. --- src/backend/catalog/index.c | 5 ++++- src/test/regress/expected/create_index.out | 12 ++++++++++++ src/test/regress/sql/create_index.sql | 8 ++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 8880586c37..1d0b1a29aa 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1527,10 +1527,13 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName) newIndexForm->indimmediate = oldIndexForm->indimmediate; oldIndexForm->indimmediate = true; + /* Preserve indisclustered */ + newIndexForm->indisclustered = oldIndexForm->indisclustered; + oldIndexForm->indisclustered = false; + /* Mark old index as valid and new as invalid as index_set_state_flags */ newIndexForm->indisvalid = true; oldIndexForm->indisvalid = false; - oldIndexForm->indisclustered = false; CatalogTupleUpdate(pg_index, &oldIndexTuple->t_self, oldIndexTuple); CatalogTupleUpdate(pg_index, &newIndexTuple->t_self, newIndexTuple); diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out index 6ddf3a63c3..2f0776bfd9 100644 --- a/src/test/regress/expected/create_index.out +++ b/src/test/regress/expected/create_index.out @@ -2128,6 +2128,18 @@ SELECT obj_description('testcomment_idx1'::regclass, 'pg_class'); (1 row) DROP TABLE testcomment; +-- Check that CLUSTER ON is preserved +CREATE TABLE concur_clustered(i int); +CREATE INDEX concur_clustered_i_idx ON concur_clustered(i); +ALTER TABLE concur_clustered CLUSTER ON concur_clustered_i_idx; +REINDEX INDEX CONCURRENTLY concur_clustered_i_idx; +SELECT indexrelid::regclass FROM pg_index WHERE indrelid='concur_clustered'::regclass; + indexrelid +------------------------ + concur_clustered_i_idx +(1 row) + +DROP TABLE concur_clustered; -- Partitions -- Create some partitioned tables CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1); diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql index f7fd756189..73f7ff395c 100644 --- a/src/test/regress/sql/create_index.sql +++ b/src/test/regress/sql/create_index.sql @@ -858,6 +858,14 @@ SELECT obj_description('testcomment_idx1'::regclass, 'pg_class'); REINDEX TABLE CONCURRENTLY testcomment ; SELECT obj_description('testcomment_idx1'::regclass, 'pg_class'); DROP TABLE testcomment; +-- Check that CLUSTER ON is preserved +CREATE TABLE concur_clustered(i int); +CREATE INDEX concur_clustered_i_idx ON concur_clustered(i); +ALTER TABLE concur_clustered CLUSTER ON concur_clustered_i_idx; +REINDEX INDEX CONCURRENTLY concur_clustered_i_idx; +SELECT indexrelid::regclass FROM pg_index WHERE indrelid='concur_clustered'::regclass; +DROP TABLE concur_clustered; + -- Partitions -- Create some partitioned tables CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1); -- 2.17.0