Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd79fb88

Browse files
committed
Preserve pg_index.indisclustered across REINDEX CONCURRENTLY
If the flag value is lost, a CLUSTER query following REINDEXCONCURRENTLY could fail. Non-concurrent REINDEX is already handlingthis case consistently.Author: Justin PryzbyDiscussion:https://postgr.es/m/20200229024202.GH29456@telsasoft.comBackpatch-through: 12
1 parent91f3bd7 commitd79fb88

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

‎src/backend/catalog/index.c

Lines changed: 7 additions & 1 deletion
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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
DROPTABLE testcomment;
861+
-- Check that indisclustered updates are preserved
862+
CREATETABLEconcur_clustered(iint);
863+
CREATEINDEXconcur_clustered_i_idxON concur_clustered(i);
864+
ALTERTABLE concur_clustered CLUSTERON concur_clustered_i_idx;
865+
REINDEX TABLE CONCURRENTLY concur_clustered;
866+
SELECT indexrelid::regclass, indisclusteredFROM pg_index
867+
WHERE indrelid='concur_clustered'::regclass;
868+
DROPTABLE concur_clustered;
869+
861870
-- Partitions
862871
-- Create some partitioned tables
863872
CREATETABLEconcur_reindex_part (c1int, c2int) PARTITION BY RANGE (c1);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp