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

Commitf087d63

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 parent3b5709e commitf087d63

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
@@ -1528,7 +1528,13 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
15281528
newIndexForm->indimmediate=oldIndexForm->indimmediate;
15291529
oldIndexForm->indimmediate= true;
15301530

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

‎src/test/regress/expected/create_index.out

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,6 +2115,19 @@ SELECT obj_description('testcomment_idx1'::regclass, 'pg_class');
21152115
(1 row)
21162116

21172117
DROP TABLE testcomment;
2118+
-- Check that indisclustered updates are preserved
2119+
CREATE TABLE concur_clustered(i int);
2120+
CREATE INDEX concur_clustered_i_idx ON concur_clustered(i);
2121+
ALTER TABLE concur_clustered CLUSTER ON concur_clustered_i_idx;
2122+
REINDEX TABLE CONCURRENTLY concur_clustered;
2123+
SELECT indexrelid::regclass, indisclustered FROM pg_index
2124+
WHERE indrelid = 'concur_clustered'::regclass;
2125+
indexrelid | indisclustered
2126+
------------------------+----------------
2127+
concur_clustered_i_idx | t
2128+
(1 row)
2129+
2130+
DROP TABLE concur_clustered;
21182131
-- Partitions
21192132
-- Create some partitioned tables
21202133
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
@@ -852,6 +852,15 @@ SELECT obj_description('testcomment_idx1'::regclass, 'pg_class');
852852
REINDEX TABLE CONCURRENTLY testcomment ;
853853
SELECT obj_description('testcomment_idx1'::regclass,'pg_class');
854854
DROPTABLE testcomment;
855+
-- Check that indisclustered updates are preserved
856+
CREATETABLEconcur_clustered(iint);
857+
CREATEINDEXconcur_clustered_i_idxON concur_clustered(i);
858+
ALTERTABLE concur_clustered CLUSTERON concur_clustered_i_idx;
859+
REINDEX TABLE CONCURRENTLY concur_clustered;
860+
SELECT indexrelid::regclass, indisclusteredFROM pg_index
861+
WHERE indrelid='concur_clustered'::regclass;
862+
DROPTABLE concur_clustered;
863+
855864
-- Partitions
856865
-- Create some partitioned tables
857866
CREATETABLEconcur_reindex_part (c1int, c2int) PARTITION BY RANGE (c1);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp