!6602 优化alter index invisible部分代码,并补充一些测试
Merge pull request !6602 from levy5307/zlw/alter-index-invisible
This commit is contained in:
@ -26473,45 +26473,7 @@ static void ATExecEnableIndex(Relation rel, bool enable) {
|
||||
|
||||
void ATExecSetIndexVisibleState(Oid objOid, bool newState)
|
||||
{
|
||||
bool dirty = false;
|
||||
Relation sys_table = NULL;
|
||||
HeapTuple sys_tuple = NULL;
|
||||
bool isNull = false;
|
||||
|
||||
sys_table = relation_open(IndexRelationId, RowExclusiveLock);
|
||||
|
||||
// update the indisvisible field
|
||||
sys_tuple = SearchSysCacheCopy1(INDEXRELID, ObjectIdGetDatum(objOid));
|
||||
if (sys_tuple) {
|
||||
Datum oldState = heap_getattr(sys_tuple, Anum_pg_index_indisvisible, RelationGetDescr(sys_table), &isNull);
|
||||
dirty = (isNull || BoolGetDatum(oldState) != newState);
|
||||
|
||||
/* Keep the system catalog indexes current. */
|
||||
if (dirty) {
|
||||
HeapTuple newitup = NULL;
|
||||
Datum values[Natts_pg_index];
|
||||
bool nulls[Natts_pg_index];
|
||||
bool replaces[Natts_pg_index];
|
||||
errno_t rc;
|
||||
rc = memset_s(values, sizeof(values), 0, sizeof(values));
|
||||
securec_check(rc, "\0", "\0");
|
||||
rc = memset_s(nulls, sizeof(nulls), false, sizeof(nulls));
|
||||
securec_check(rc, "\0", "\0");
|
||||
rc = memset_s(replaces, sizeof(replaces), false, sizeof(replaces));
|
||||
securec_check(rc, "\0", "\0");
|
||||
|
||||
replaces[Anum_pg_index_indisvisible - 1] = true;
|
||||
values[Anum_pg_index_indisvisible - 1] = DatumGetBool(newState);
|
||||
|
||||
newitup =
|
||||
(HeapTuple)tableam_tops_modify_tuple(sys_tuple, RelationGetDescr(sys_table), values, nulls, replaces);
|
||||
simple_heap_update(sys_table, &(sys_tuple->t_self), newitup);
|
||||
CatalogUpdateIndexes(sys_table, newitup);
|
||||
tableam_tops_free_tuple(newitup);
|
||||
}
|
||||
tableam_tops_free_tuple(sys_tuple);
|
||||
}
|
||||
relation_close(sys_table, RowExclusiveLock);
|
||||
ATExecSetIndexState(objOid, Anum_pg_index_indisvisible, newState);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -15,9 +15,9 @@ alter index func_idx_alter_index_disable disable;
|
||||
|
||||
\c db_restore
|
||||
-- the function-based index `func_idx_alter_index_disable` was disabled
|
||||
explain select * from alter_index_disable where to_char(a) = '1';
|
||||
explain (costs off) select * from alter_index_disable where to_char(a) = '1';
|
||||
alter index func_idx_alter_index_disable enable;
|
||||
explain select * from alter_index_disable where to_char(a) = '1';
|
||||
explain (costs off) select * from alter_index_disable where to_char(a) = '1';
|
||||
|
||||
\c postgres
|
||||
drop database db_alter_index_disable;
|
||||
|
||||
24
src/test/regress/input/dump_alter_index_invisible.source
Normal file
24
src/test/regress/input/dump_alter_index_invisible.source
Normal file
@ -0,0 +1,24 @@
|
||||
create user u_alter_invisible password '1234@abcd';
|
||||
grant all privileges to u_alter_invisible;
|
||||
|
||||
create database db_alter_index_invisible;
|
||||
create database db_restore;
|
||||
|
||||
\c db_alter_index_invisible
|
||||
create table alter_index_invisible (a int, b int);
|
||||
create index idx_alter_index_invisible on alter_index_invisible(a);
|
||||
alter index idx_alter_index_invisible invisible;
|
||||
|
||||
\! @abs_bindir@/gs_dump -p @portstring@ db_alter_index_invisible -f @abs_bindir@/dump -F c -w > @abs_bindir@/gs_dump_alter_invisible.log 2>&1 ; echo $?
|
||||
|
||||
\! @abs_bindir@/gs_restore -h 127.0.0.1 -p @portstring@ -U u_alter_invisible -W 1234@abcd -d db_restore -F c @abs_bindir@/dump > @abs_bindir@/gs_dump_alter_invisible.log 2>&1 ; echo $?
|
||||
|
||||
\c db_restore
|
||||
-- the index `idx_alter_index_invisible` is invisible
|
||||
explain (costs off) select * from alter_index_invisible where a = 1;
|
||||
alter index idx_alter_index_invisible visible;
|
||||
explain (costs off) select * from alter_index_invisible where a = 1;
|
||||
|
||||
\c postgres
|
||||
drop database db_alter_index_invisible;
|
||||
drop database db_restore;
|
||||
@ -12,20 +12,20 @@ alter index func_idx_alter_index_disable disable;
|
||||
0
|
||||
\c db_restore
|
||||
-- the function-based index `func_idx_alter_index_disable` was disabled
|
||||
explain select * from alter_index_disable where to_char(a) = '1';
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------
|
||||
Seq Scan on alter_index_disable (cost=0.00..52.98 rows=11 width=8)
|
||||
explain (costs off) select * from alter_index_disable where to_char(a) = '1';
|
||||
QUERY PLAN
|
||||
-----------------------------------------------------------------
|
||||
Seq Scan on alter_index_disable
|
||||
Filter: (((int4out(a))::character varying)::text = '1'::text)
|
||||
(2 rows)
|
||||
|
||||
alter index func_idx_alter_index_disable enable;
|
||||
explain select * from alter_index_disable where to_char(a) = '1';
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------
|
||||
Bitmap Heap Scan on alter_index_disable (cost=4.34..15.10 rows=11 width=8)
|
||||
explain (costs off) select * from alter_index_disable where to_char(a) = '1';
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------------
|
||||
Bitmap Heap Scan on alter_index_disable
|
||||
Recheck Cond: (((int4out(a))::character varying)::text = '1'::text)
|
||||
-> Bitmap Index Scan on func_idx_alter_index_disable (cost=0.00..4.34 rows=11 width=0)
|
||||
-> Bitmap Index Scan on func_idx_alter_index_disable
|
||||
Index Cond: (((int4out(a))::character varying)::text = '1'::text)
|
||||
(4 rows)
|
||||
|
||||
|
||||
34
src/test/regress/output/dump_alter_index_invisible.source
Normal file
34
src/test/regress/output/dump_alter_index_invisible.source
Normal file
@ -0,0 +1,34 @@
|
||||
create user u_alter_invisible password '1234@abcd';
|
||||
grant all privileges to u_alter_invisible;
|
||||
create database db_alter_index_invisible;
|
||||
create database db_restore;
|
||||
\c db_alter_index_invisible
|
||||
create table alter_index_invisible (a int, b int);
|
||||
create index idx_alter_index_invisible on alter_index_invisible(a);
|
||||
alter index idx_alter_index_invisible invisible;
|
||||
\! @abs_bindir@/gs_dump -p @portstring@ db_alter_index_invisible -f @abs_bindir@/dump -F c -w > @abs_bindir@/gs_dump_alter_invisible.log 2>&1 ; echo $?
|
||||
0
|
||||
\! @abs_bindir@/gs_restore -h 127.0.0.1 -p @portstring@ -U u_alter_invisible -W 1234@abcd -d db_restore -F c @abs_bindir@/dump > @abs_bindir@/gs_dump_alter_invisible.log 2>&1 ; echo $?
|
||||
0
|
||||
\c db_restore
|
||||
-- the index `idx_alter_index_invisible` is invisible
|
||||
explain (costs off) select * from alter_index_invisible where a = 1;
|
||||
QUERY PLAN
|
||||
-----------------------------------
|
||||
Seq Scan on alter_index_invisible
|
||||
Filter: (a = 1)
|
||||
(2 rows)
|
||||
|
||||
alter index idx_alter_index_invisible visible;
|
||||
explain (costs off) select * from alter_index_invisible where a = 1;
|
||||
QUERY PLAN
|
||||
------------------------------------------------------
|
||||
Bitmap Heap Scan on alter_index_invisible
|
||||
Recheck Cond: (a = 1)
|
||||
-> Bitmap Index Scan on idx_alter_index_invisible
|
||||
Index Cond: (a = 1)
|
||||
(4 rows)
|
||||
|
||||
\c postgres
|
||||
drop database db_alter_index_invisible;
|
||||
drop database db_restore;
|
||||
@ -1149,3 +1149,5 @@ test: dump_alter_index_disable
|
||||
|
||||
# to_timestamp func
|
||||
test: to_timestamp_default
|
||||
|
||||
test: dump_alter_index_invisible
|
||||
|
||||
@ -200,4 +200,6 @@ test: to_number_default
|
||||
test: to_timestamp_default
|
||||
|
||||
test: alter_index_disable
|
||||
test: dump_alter_index_disable
|
||||
test: dump_alter_index_disable
|
||||
|
||||
test: dump_alter_index_invisible
|
||||
Reference in New Issue
Block a user