@ -4441,6 +4441,10 @@ static bool ReindexRelationConcurrently(Oid relationOid, Oid relationPartOid, Ad
|
||||
CommandCounterIncrement();
|
||||
}
|
||||
|
||||
// call the internal function, if index is unusable, set it usable
|
||||
ATExecSetIndexUsableState(IndexRelationId, oldIndexId, true);
|
||||
CacheInvalidateRelcacheByRelid(heapId);
|
||||
|
||||
/*
|
||||
* swap index id for drop new partitioned index, because this new partitioned
|
||||
* index has old index partitions.
|
||||
|
||||
@ -221,6 +221,41 @@ Indexes:
|
||||
"concur_reindex_ind5" UNIQUE, btree (c1) TABLESPACE pg_default
|
||||
|
||||
DROP TABLE concur_reindex_tab4;
|
||||
-- Check handling of unusable indexes
|
||||
CREATE TABLE concur_reindex_tab5 (c1 int);
|
||||
CREATE INDEX concur_reindex_ind6 ON concur_reindex_tab5(c1);
|
||||
-- Set concur_reindex_ind6 unusable
|
||||
ALTER INDEX concur_reindex_ind6 UNUSABLE;
|
||||
\d concur_reindex_tab5
|
||||
Table "public.concur_reindex_tab5"
|
||||
Column | Type | Modifiers
|
||||
--------+---------+-----------
|
||||
c1 | integer |
|
||||
Indexes:
|
||||
"concur_reindex_ind6" btree (c1) TABLESPACE pg_default UNUSABLE
|
||||
|
||||
-- The unusable index is not processed when running REINDEX TABLE.
|
||||
REINDEX TABLE CONCURRENTLY concur_reindex_tab5;
|
||||
NOTICE: table "concur_reindex_tab5" has no indexes
|
||||
\d concur_reindex_tab5
|
||||
Table "public.concur_reindex_tab5"
|
||||
Column | Type | Modifiers
|
||||
--------+---------+-----------
|
||||
c1 | integer |
|
||||
Indexes:
|
||||
"concur_reindex_ind6" btree (c1) TABLESPACE pg_default UNUSABLE
|
||||
|
||||
-- But it is fixes with REINDEX INDEX
|
||||
REINDEX INDEX CONCURRENTLY concur_reindex_ind6;
|
||||
\d concur_reindex_tab5
|
||||
Table "public.concur_reindex_tab5"
|
||||
Column | Type | Modifiers
|
||||
--------+---------+-----------
|
||||
c1 | integer |
|
||||
Indexes:
|
||||
"concur_reindex_ind6" btree (c1) TABLESPACE pg_default
|
||||
|
||||
DROP TABLE concur_reindex_tab5;
|
||||
-- Check handling of indexes with expressions and predicates. The
|
||||
-- definitions of the rebuilt indexes should match the original
|
||||
-- definitions.
|
||||
|
||||
@ -43,7 +43,78 @@ reindex index CONCURRENTLY idx_t1;
|
||||
reindex index CONCURRENTLY idx2_t1 partition t1_1_index;
|
||||
reindex table CONCURRENTLY t1;
|
||||
reindex table CONCURRENTLY t1 partition t1_1;
|
||||
-- Check handling of unusable partition index
|
||||
-- Check handling of unusable partitioned index
|
||||
alter index idx2_t1 UNUSABLE;
|
||||
\d t1
|
||||
Table "public.t1"
|
||||
Column | Type | Modifiers
|
||||
--------+--------------------------------+-----------
|
||||
c_id | character varying |
|
||||
c_w_id | integer |
|
||||
c_date | timestamp(0) without time zone |
|
||||
Indexes:
|
||||
"idx2_t1" btree (c_id) LOCAL TABLESPACE pg_default UNUSABLE
|
||||
"idx_t1" btree (c_id) LOCAL TABLESPACE pg_default
|
||||
Partition By RANGE(c_date, c_w_id)
|
||||
Number of partitions: 8 (View pg_partition to check each partition range.)
|
||||
|
||||
reindex table concurrently t1;
|
||||
\d t1
|
||||
Table "public.t1"
|
||||
Column | Type | Modifiers
|
||||
--------+--------------------------------+-----------
|
||||
c_id | character varying |
|
||||
c_w_id | integer |
|
||||
c_date | timestamp(0) without time zone |
|
||||
Indexes:
|
||||
"idx2_t1" btree (c_id) LOCAL TABLESPACE pg_default UNUSABLE
|
||||
"idx_t1" btree (c_id) LOCAL TABLESPACE pg_default
|
||||
Partition By RANGE(c_date, c_w_id)
|
||||
Number of partitions: 8 (View pg_partition to check each partition range.)
|
||||
|
||||
reindex table concurrently t1 partition t1_1;
|
||||
\d t1
|
||||
Table "public.t1"
|
||||
Column | Type | Modifiers
|
||||
--------+--------------------------------+-----------
|
||||
c_id | character varying |
|
||||
c_w_id | integer |
|
||||
c_date | timestamp(0) without time zone |
|
||||
Indexes:
|
||||
"idx2_t1" btree (c_id) LOCAL TABLESPACE pg_default UNUSABLE
|
||||
"idx_t1" btree (c_id) LOCAL TABLESPACE pg_default
|
||||
Partition By RANGE(c_date, c_w_id)
|
||||
Number of partitions: 8 (View pg_partition to check each partition range.)
|
||||
|
||||
reindex index concurrently idx2_t1 partition t1_1_index;
|
||||
\d t1
|
||||
Table "public.t1"
|
||||
Column | Type | Modifiers
|
||||
--------+--------------------------------+-----------
|
||||
c_id | character varying |
|
||||
c_w_id | integer |
|
||||
c_date | timestamp(0) without time zone |
|
||||
Indexes:
|
||||
"idx2_t1" btree (c_id) LOCAL TABLESPACE pg_default UNUSABLE
|
||||
"idx_t1" btree (c_id) LOCAL TABLESPACE pg_default
|
||||
Partition By RANGE(c_date, c_w_id)
|
||||
Number of partitions: 8 (View pg_partition to check each partition range.)
|
||||
|
||||
reindex index concurrently idx2_t1;
|
||||
\d t1
|
||||
Table "public.t1"
|
||||
Column | Type | Modifiers
|
||||
--------+--------------------------------+-----------
|
||||
c_id | character varying |
|
||||
c_w_id | integer |
|
||||
c_date | timestamp(0) without time zone |
|
||||
Indexes:
|
||||
"idx2_t1" btree (c_id) LOCAL TABLESPACE pg_default
|
||||
"idx_t1" btree (c_id) LOCAL TABLESPACE pg_default
|
||||
Partition By RANGE(c_date, c_w_id)
|
||||
Number of partitions: 8 (View pg_partition to check each partition range.)
|
||||
|
||||
-- Check handling of unusable index partition
|
||||
alter index idx2_t1 modify partition t1_2_index UNUSABLE;
|
||||
select indisusable from pg_partition where relname = 't1_2_index';
|
||||
indisusable
|
||||
|
||||
@ -133,6 +133,20 @@ REINDEX INDEX CONCURRENTLY concur_reindex_ind5;
|
||||
\d concur_reindex_tab4
|
||||
DROP TABLE concur_reindex_tab4;
|
||||
|
||||
-- Check handling of unusable indexes
|
||||
CREATE TABLE concur_reindex_tab5 (c1 int);
|
||||
CREATE INDEX concur_reindex_ind6 ON concur_reindex_tab5(c1);
|
||||
-- Set concur_reindex_ind6 unusable
|
||||
ALTER INDEX concur_reindex_ind6 UNUSABLE;
|
||||
\d concur_reindex_tab5
|
||||
-- The unusable index is not processed when running REINDEX TABLE.
|
||||
REINDEX TABLE CONCURRENTLY concur_reindex_tab5;
|
||||
\d concur_reindex_tab5
|
||||
-- But it is fixes with REINDEX INDEX
|
||||
REINDEX INDEX CONCURRENTLY concur_reindex_ind6;
|
||||
\d concur_reindex_tab5
|
||||
DROP TABLE concur_reindex_tab5;
|
||||
|
||||
-- Check handling of indexes with expressions and predicates. The
|
||||
-- definitions of the rebuilt indexes should match the original
|
||||
-- definitions.
|
||||
|
||||
@ -46,7 +46,19 @@ reindex index CONCURRENTLY idx2_t1 partition t1_1_index;
|
||||
reindex table CONCURRENTLY t1;
|
||||
reindex table CONCURRENTLY t1 partition t1_1;
|
||||
|
||||
-- Check handling of unusable partition index
|
||||
-- Check handling of unusable partitioned index
|
||||
alter index idx2_t1 UNUSABLE;
|
||||
\d t1
|
||||
reindex table concurrently t1;
|
||||
\d t1
|
||||
reindex table concurrently t1 partition t1_1;
|
||||
\d t1
|
||||
reindex index concurrently idx2_t1 partition t1_1_index;
|
||||
\d t1
|
||||
reindex index concurrently idx2_t1;
|
||||
\d t1
|
||||
|
||||
-- Check handling of unusable index partition
|
||||
alter index idx2_t1 modify partition t1_2_index UNUSABLE;
|
||||
select indisusable from pg_partition where relname = 't1_2_index';
|
||||
reindex table CONCURRENTLY t1;
|
||||
|
||||
Reference in New Issue
Block a user