diff --git a/src/gausskernel/optimizer/commands/indexcmds.cpp b/src/gausskernel/optimizer/commands/indexcmds.cpp index 0beecf777..9b31df565 100755 --- a/src/gausskernel/optimizer/commands/indexcmds.cpp +++ b/src/gausskernel/optimizer/commands/indexcmds.cpp @@ -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. diff --git a/src/test/regress/expected/reindex_concurrently.out b/src/test/regress/expected/reindex_concurrently.out index 79c7f774a..0dbd74852 100644 --- a/src/test/regress/expected/reindex_concurrently.out +++ b/src/test/regress/expected/reindex_concurrently.out @@ -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. diff --git a/src/test/regress/expected/reindex_concurrently_partition.out b/src/test/regress/expected/reindex_concurrently_partition.out index c742b6eb6..c71a9de4a 100644 --- a/src/test/regress/expected/reindex_concurrently_partition.out +++ b/src/test/regress/expected/reindex_concurrently_partition.out @@ -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 diff --git a/src/test/regress/sql/reindex_concurrently.sql b/src/test/regress/sql/reindex_concurrently.sql index 78b802d2f..c10aeb0ea 100644 --- a/src/test/regress/sql/reindex_concurrently.sql +++ b/src/test/regress/sql/reindex_concurrently.sql @@ -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. diff --git a/src/test/regress/sql/reindex_concurrently_partition.sql b/src/test/regress/sql/reindex_concurrently_partition.sql index 09ce24e01..e543f9162 100644 --- a/src/test/regress/sql/reindex_concurrently_partition.sql +++ b/src/test/regress/sql/reindex_concurrently_partition.sql @@ -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;