mirror of
https://github.com/postgres/postgres.git
synced 2025-05-15 19:15:29 +03:00
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
This commit is contained in:
parent
3b5709e664
commit
f087d63a45
@ -1528,7 +1528,13 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
|
|||||||
newIndexForm->indimmediate = oldIndexForm->indimmediate;
|
newIndexForm->indimmediate = oldIndexForm->indimmediate;
|
||||||
oldIndexForm->indimmediate = true;
|
oldIndexForm->indimmediate = true;
|
||||||
|
|
||||||
/* Mark old index as valid and new as invalid as index_set_state_flags */
|
/* Preserve indisclustered in the new index */
|
||||||
|
newIndexForm->indisclustered = oldIndexForm->indisclustered;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Mark the old index as valid, and the new index as invalid similarly
|
||||||
|
* to what index_set_state_flags() does.
|
||||||
|
*/
|
||||||
newIndexForm->indisvalid = true;
|
newIndexForm->indisvalid = true;
|
||||||
oldIndexForm->indisvalid = false;
|
oldIndexForm->indisvalid = false;
|
||||||
oldIndexForm->indisclustered = false;
|
oldIndexForm->indisclustered = false;
|
||||||
|
@ -2115,6 +2115,19 @@ SELECT obj_description('testcomment_idx1'::regclass, 'pg_class');
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
DROP TABLE testcomment;
|
DROP TABLE testcomment;
|
||||||
|
-- Check that indisclustered updates are 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 TABLE CONCURRENTLY concur_clustered;
|
||||||
|
SELECT indexrelid::regclass, indisclustered FROM pg_index
|
||||||
|
WHERE indrelid = 'concur_clustered'::regclass;
|
||||||
|
indexrelid | indisclustered
|
||||||
|
------------------------+----------------
|
||||||
|
concur_clustered_i_idx | t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
DROP TABLE concur_clustered;
|
||||||
-- Partitions
|
-- Partitions
|
||||||
-- Create some partitioned tables
|
-- Create some partitioned tables
|
||||||
CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1);
|
CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1);
|
||||||
|
@ -852,6 +852,15 @@ SELECT obj_description('testcomment_idx1'::regclass, 'pg_class');
|
|||||||
REINDEX TABLE CONCURRENTLY testcomment ;
|
REINDEX TABLE CONCURRENTLY testcomment ;
|
||||||
SELECT obj_description('testcomment_idx1'::regclass, 'pg_class');
|
SELECT obj_description('testcomment_idx1'::regclass, 'pg_class');
|
||||||
DROP TABLE testcomment;
|
DROP TABLE testcomment;
|
||||||
|
-- Check that indisclustered updates are 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 TABLE CONCURRENTLY concur_clustered;
|
||||||
|
SELECT indexrelid::regclass, indisclustered FROM pg_index
|
||||||
|
WHERE indrelid = 'concur_clustered'::regclass;
|
||||||
|
DROP TABLE concur_clustered;
|
||||||
|
|
||||||
-- Partitions
|
-- Partitions
|
||||||
-- Create some partitioned tables
|
-- Create some partitioned tables
|
||||||
CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1);
|
CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user