Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d79fb88

Browse files
committed
Preserve pg_index.indisclustered across REINDEX CONCURRENTLY
If the flag value is lost, a CLUSTER query following REINDEX CONCURRENTLY could fail. Non-concurrent REINDEX is already handling this case consistently. Author: Justin Pryzby Discussion: https://postgr.es/m/20200229024202.GH29456@telsasoft.com Backpatch-through: 12
1 parent 91f3bd7 commit d79fb88

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/backend/catalog/index.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,13 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
15271527
newIndexForm->indimmediate = oldIndexForm->indimmediate;
15281528
oldIndexForm->indimmediate = true;
15291529

1530-
/* Mark old index as valid and new as invalid as index_set_state_flags */
1530+
/* Preserve indisclustered in the new index */
1531+
newIndexForm->indisclustered = oldIndexForm->indisclustered;
1532+
1533+
/*
1534+
* Mark the old index as valid, and the new index as invalid similarly
1535+
* to what index_set_state_flags() does.
1536+
*/
15311537
newIndexForm->indisvalid = true;
15321538
oldIndexForm->indisvalid = false;
15331539
oldIndexForm->indisclustered = false;

src/test/regress/expected/create_index.out

+13
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,19 @@ SELECT obj_description('testcomment_idx1'::regclass, 'pg_class');
21282128
(1 row)
21292129

21302130
DROP TABLE testcomment;
2131+
-- Check that indisclustered updates are preserved
2132+
CREATE TABLE concur_clustered(i int);
2133+
CREATE INDEX concur_clustered_i_idx ON concur_clustered(i);
2134+
ALTER TABLE concur_clustered CLUSTER ON concur_clustered_i_idx;
2135+
REINDEX TABLE CONCURRENTLY concur_clustered;
2136+
SELECT indexrelid::regclass, indisclustered FROM pg_index
2137+
WHERE indrelid = 'concur_clustered'::regclass;
2138+
indexrelid | indisclustered
2139+
------------------------+----------------
2140+
concur_clustered_i_idx | t
2141+
(1 row)
2142+
2143+
DROP TABLE concur_clustered;
21312144
-- Partitions
21322145
-- Create some partitioned tables
21332146
CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1);

src/test/regress/sql/create_index.sql

+9
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,15 @@ SELECT obj_description('testcomment_idx1'::regclass, 'pg_class');
858858
REINDEX TABLE CONCURRENTLY testcomment ;
859859
SELECT obj_description('testcomment_idx1'::regclass, 'pg_class');
860860
DROP TABLE testcomment;
861+
-- Check that indisclustered updates are preserved
862+
CREATE TABLE concur_clustered(i int);
863+
CREATE INDEX concur_clustered_i_idx ON concur_clustered(i);
864+
ALTER TABLE concur_clustered CLUSTER ON concur_clustered_i_idx;
865+
REINDEX TABLE CONCURRENTLY concur_clustered;
866+
SELECT indexrelid::regclass, indisclustered FROM pg_index
867+
WHERE indrelid = 'concur_clustered'::regclass;
868+
DROP TABLE concur_clustered;
869+
861870
-- Partitions
862871
-- Create some partitioned tables
863872
CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1);

0 commit comments

Comments
 (0)