CREATE/ALTER INDEX支持设置可见性
This commit is contained in:
@ -4651,9 +4651,22 @@ alter_table_cmd:
|
|||||||
$$ = (Node *)n;
|
$$ = (Node *)n;
|
||||||
}
|
}
|
||||||
|
|
|
|
||||||
|
INVISIBLE
|
||||||
|
{
|
||||||
|
AlterTableCmd *n = makeNode(AlterTableCmd);
|
||||||
|
n->subtype = AT_InvisibleIndexDirect;
|
||||||
|
$$ = (Node *)n;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
VISIBLE
|
||||||
|
{
|
||||||
|
AlterTableCmd *n = makeNode(AlterTableCmd);
|
||||||
|
n->subtype = AT_VisibleIndexDirect;
|
||||||
|
$$ = (Node *)n;
|
||||||
|
}
|
||||||
|
|
|
||||||
ALTER INDEX index_name INVISIBLE
|
ALTER INDEX index_name INVISIBLE
|
||||||
{
|
{
|
||||||
BCompatibilityOptionSupportCheck($4);
|
|
||||||
AlterTableCmd *n = makeNode(AlterTableCmd);
|
AlterTableCmd *n = makeNode(AlterTableCmd);
|
||||||
n->subtype = AT_InvisibleIndex;
|
n->subtype = AT_InvisibleIndex;
|
||||||
n->name = $3;
|
n->name = $3;
|
||||||
@ -4662,7 +4675,6 @@ alter_table_cmd:
|
|||||||
|
|
|
|
||||||
ALTER INDEX index_name VISIBLE
|
ALTER INDEX index_name VISIBLE
|
||||||
{
|
{
|
||||||
BCompatibilityOptionSupportCheck($4);
|
|
||||||
AlterTableCmd *n = makeNode(AlterTableCmd);
|
AlterTableCmd *n = makeNode(AlterTableCmd);
|
||||||
n->subtype = AT_VisibleIndex;
|
n->subtype = AT_VisibleIndex;
|
||||||
n->name = $3;
|
n->name = $3;
|
||||||
@ -5440,13 +5452,11 @@ table_index_option:
|
|||||||
}
|
}
|
||||||
| INVISIBLE
|
| INVISIBLE
|
||||||
{
|
{
|
||||||
BCompatibilityOptionSupportCheck($1);
|
|
||||||
Value *n = makeString("invisible");
|
Value *n = makeString("invisible");
|
||||||
$$ = (Node*)n;
|
$$ = (Node*)n;
|
||||||
}
|
}
|
||||||
| VISIBLE
|
| VISIBLE
|
||||||
{
|
{
|
||||||
BCompatibilityOptionSupportCheck($1);
|
|
||||||
Value *n = makeString("visible");
|
Value *n = makeString("visible");
|
||||||
$$ = (Node*)n;
|
$$ = (Node*)n;
|
||||||
}
|
}
|
||||||
|
@ -681,6 +681,7 @@ static void ATExecUnusableIndex(Relation rel);
|
|||||||
static void ATUnusableGlobalIndex(Relation rel);
|
static void ATUnusableGlobalIndex(Relation rel);
|
||||||
static void ATExecUnusableAllIndexOnPartition(Relation rel, const char* partition_name);
|
static void ATExecUnusableAllIndexOnPartition(Relation rel, const char* partition_name);
|
||||||
static void ATExecVisibleIndex(Relation rel, char* index_name, bool visible);
|
static void ATExecVisibleIndex(Relation rel, char* index_name, bool visible);
|
||||||
|
static void ATExecVisibleIndexDirect(Relation rel, bool visible);
|
||||||
static void ATExecModifyRowMovement(Relation rel, bool rowMovement);
|
static void ATExecModifyRowMovement(Relation rel, bool rowMovement);
|
||||||
static void ATExecTruncatePartition(Relation rel, AlterTableCmd* cmd);
|
static void ATExecTruncatePartition(Relation rel, AlterTableCmd* cmd);
|
||||||
static void ATExecTruncateSubPartition(Relation rel, AlterTableCmd* cmd);
|
static void ATExecTruncateSubPartition(Relation rel, AlterTableCmd* cmd);
|
||||||
@ -829,6 +830,8 @@ inline static bool CStoreSupportATCmd(AlterTableType cmdtype)
|
|||||||
#endif
|
#endif
|
||||||
case AT_VisibleIndex:
|
case AT_VisibleIndex:
|
||||||
case AT_InvisibleIndex:
|
case AT_InvisibleIndex:
|
||||||
|
case AT_InvisibleIndexDirect:
|
||||||
|
case AT_VisibleIndexDirect:
|
||||||
ret = true;
|
ret = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -8432,6 +8435,8 @@ static void ATPrepCmd(List** wqueue, Relation rel, AlterTableCmd* cmd, bool recu
|
|||||||
case AT_ReplaceRelOptions: /* reset them all, then set just these */
|
case AT_ReplaceRelOptions: /* reset them all, then set just these */
|
||||||
case AT_InvisibleIndex:
|
case AT_InvisibleIndex:
|
||||||
case AT_VisibleIndex:
|
case AT_VisibleIndex:
|
||||||
|
case AT_InvisibleIndexDirect:
|
||||||
|
case AT_VisibleIndexDirect:
|
||||||
ATSimplePermissions(rel, ATT_TABLE | ATT_INDEX | ATT_VIEW);
|
ATSimplePermissions(rel, ATT_TABLE | ATT_INDEX | ATT_VIEW);
|
||||||
/* This command never recurses */
|
/* This command never recurses */
|
||||||
/* No command-specific prep needed */
|
/* No command-specific prep needed */
|
||||||
@ -9060,6 +9065,12 @@ static void ATExecCmd(List** wqueue, AlteredTableInfo* tab, Relation rel, AlterT
|
|||||||
case AT_VisibleIndex:
|
case AT_VisibleIndex:
|
||||||
ATExecVisibleIndex(rel, cmd->name, true);
|
ATExecVisibleIndex(rel, cmd->name, true);
|
||||||
break;
|
break;
|
||||||
|
case AT_InvisibleIndexDirect:
|
||||||
|
ATExecVisibleIndexDirect(rel, false);
|
||||||
|
break;
|
||||||
|
case AT_VisibleIndexDirect:
|
||||||
|
ATExecVisibleIndexDirect(rel, true);
|
||||||
|
break;
|
||||||
case AT_AddIndex: /* ADD INDEX */
|
case AT_AddIndex: /* ADD INDEX */
|
||||||
address = ATExecAddIndex(tab, rel, (IndexStmt*)cmd->def, false, lockmode);
|
address = ATExecAddIndex(tab, rel, (IndexStmt*)cmd->def, false, lockmode);
|
||||||
break;
|
break;
|
||||||
@ -25425,6 +25436,18 @@ static void ATExecVisibleIndex(Relation rel, char* index_name, bool visible)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ATExecVisibleIndexDirect(Relation rel, bool visible)
|
||||||
|
{
|
||||||
|
if (RelationIsIndex(rel) && OidIsValid(rel->rd_id)) {
|
||||||
|
ATExecSetIndexVisibleState(rel->rd_id, visible);
|
||||||
|
} else {
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||||
|
errmsg("can not set visible for relation %s, as it is not a index",
|
||||||
|
RelationGetRelationName(rel))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @@GaussDB@@
|
* @@GaussDB@@
|
||||||
* Target : data partition
|
* Target : data partition
|
||||||
|
@ -915,6 +915,8 @@ typedef enum AlterTableType {
|
|||||||
AT_COMMENTS,
|
AT_COMMENTS,
|
||||||
AT_InvisibleIndex,
|
AT_InvisibleIndex,
|
||||||
AT_VisibleIndex,
|
AT_VisibleIndex,
|
||||||
|
AT_InvisibleIndexDirect,
|
||||||
|
AT_VisibleIndexDirect,
|
||||||
AT_ModifyColumn,
|
AT_ModifyColumn,
|
||||||
AT_SetCharsetCollate,
|
AT_SetCharsetCollate,
|
||||||
AT_ConvertCharset,
|
AT_ConvertCharset,
|
||||||
|
@ -1,17 +1,53 @@
|
|||||||
/* unsupported */
|
/* unsupported */
|
||||||
create schema invisible_index;
|
create schema invisible_index;
|
||||||
set search_path to 'invisible_index';
|
set search_path to 'invisible_index';
|
||||||
create table t1 (a int, b int, constraint key_a primary key(a) visible); --error
|
create table t1 (a int, b int, constraint key1 primary key(a) visible);
|
||||||
ERROR: visible is supported only in B compatible database.
|
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "key1" for table "t1"
|
||||||
create table t1 (a int, b int, constraint key_a primary key(a));
|
alter table t1 alter index key1 invisible;
|
||||||
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "key_a" for table "t1"
|
alter table t1 add constraint key2 unique (b) visible;
|
||||||
alter table t1 alter index key_a invisible; --error
|
NOTICE: ALTER TABLE / ADD UNIQUE will create implicit index "key2" for table "t1"
|
||||||
ERROR: invisible is supported only in B compatible database.
|
create table t2 (a int, b int, constraint key3 primary key(a) invisible);
|
||||||
alter table t1 add constraint key_b unique (b) visible; --error
|
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "key3" for table "t2"
|
||||||
ERROR: visible is supported only in B compatible database.
|
alter table t2 alter index key3 visible;
|
||||||
|
alter table t2 add constraint key4 unique (b) invisible;
|
||||||
|
NOTICE: ALTER TABLE / ADD UNIQUE will create implicit index "key4" for table "t2"
|
||||||
|
create table t3 (a int, b int);
|
||||||
|
create index key5 on t3(a) visible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't3'::regclass order by indkey;
|
||||||
|
indkey | indisvisible
|
||||||
|
--------+--------------
|
||||||
|
1 | t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
alter index key5 invisible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't3'::regclass order by indkey;
|
||||||
|
indkey | indisvisible
|
||||||
|
--------+--------------
|
||||||
|
1 | f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
create table t4 (a int, b int);
|
||||||
|
create index key6 on t4(a) invisible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't4'::regclass order by indkey;
|
||||||
|
indkey | indisvisible
|
||||||
|
--------+--------------
|
||||||
|
1 | f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
alter index key6 visible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't4'::regclass order by indkey;
|
||||||
|
indkey | indisvisible
|
||||||
|
--------+--------------
|
||||||
|
1 | t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
reset search_path;
|
reset search_path;
|
||||||
drop schema invisible_index cascade;
|
drop schema invisible_index cascade;
|
||||||
NOTICE: drop cascades to table invisible_index.t1
|
NOTICE: drop cascades to 4 other objects
|
||||||
|
DETAIL: drop cascades to table invisible_index.t1
|
||||||
|
drop cascades to table invisible_index.t2
|
||||||
|
drop cascades to table invisible_index.t3
|
||||||
|
drop cascades to table invisible_index.t4
|
||||||
create database invisible_index_db dbcompatibility 'B';
|
create database invisible_index_db dbcompatibility 'B';
|
||||||
\c invisible_index_db
|
\c invisible_index_db
|
||||||
-- create table with index
|
-- create table with index
|
||||||
@ -26,6 +62,36 @@ select indkey, indisvisible from pg_index where indrelid = 't1'::regclass order
|
|||||||
2 | f
|
2 | f
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
|
create table t3 (a int, b int);
|
||||||
|
create index key5 on t3(a) visible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't3'::regclass order by indkey;
|
||||||
|
indkey | indisvisible
|
||||||
|
--------+--------------
|
||||||
|
1 | t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
alter index key5 invisible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't3'::regclass order by indkey;
|
||||||
|
indkey | indisvisible
|
||||||
|
--------+--------------
|
||||||
|
1 | f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
create table t4 (a int, b int);
|
||||||
|
create index key6 on t4(a) invisible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't4'::regclass order by indkey;
|
||||||
|
indkey | indisvisible
|
||||||
|
--------+--------------
|
||||||
|
1 | f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
alter index key6 visible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't4'::regclass order by indkey;
|
||||||
|
indkey | indisvisible
|
||||||
|
--------+--------------
|
||||||
|
1 | t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
insert into t1 values (generate_series(1, 100), generate_series(1, 100));
|
insert into t1 values (generate_series(1, 100), generate_series(1, 100));
|
||||||
analyze t1;
|
analyze t1;
|
||||||
set enable_seqscan = off;
|
set enable_seqscan = off;
|
||||||
|
@ -2,11 +2,25 @@
|
|||||||
create schema invisible_index;
|
create schema invisible_index;
|
||||||
set search_path to 'invisible_index';
|
set search_path to 'invisible_index';
|
||||||
|
|
||||||
create table t1 (a int, b int, constraint key_a primary key(a) visible); --error
|
create table t1 (a int, b int, constraint key1 primary key(a) visible);
|
||||||
|
alter table t1 alter index key1 invisible;
|
||||||
|
alter table t1 add constraint key2 unique (b) visible;
|
||||||
|
|
||||||
create table t1 (a int, b int, constraint key_a primary key(a));
|
create table t2 (a int, b int, constraint key3 primary key(a) invisible);
|
||||||
alter table t1 alter index key_a invisible; --error
|
alter table t2 alter index key3 visible;
|
||||||
alter table t1 add constraint key_b unique (b) visible; --error
|
alter table t2 add constraint key4 unique (b) invisible;
|
||||||
|
|
||||||
|
create table t3 (a int, b int);
|
||||||
|
create index key5 on t3(a) visible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't3'::regclass order by indkey;
|
||||||
|
alter index key5 invisible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't3'::regclass order by indkey;
|
||||||
|
|
||||||
|
create table t4 (a int, b int);
|
||||||
|
create index key6 on t4(a) invisible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't4'::regclass order by indkey;
|
||||||
|
alter index key6 visible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't4'::regclass order by indkey;
|
||||||
|
|
||||||
reset search_path;
|
reset search_path;
|
||||||
drop schema invisible_index cascade;
|
drop schema invisible_index cascade;
|
||||||
@ -21,6 +35,18 @@ alter table t1 alter index key_b visible, alter index key_b invisible;
|
|||||||
|
|
||||||
select indkey, indisvisible from pg_index where indrelid = 't1'::regclass order by indkey;
|
select indkey, indisvisible from pg_index where indrelid = 't1'::regclass order by indkey;
|
||||||
|
|
||||||
|
create table t3 (a int, b int);
|
||||||
|
create index key5 on t3(a) visible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't3'::regclass order by indkey;
|
||||||
|
alter index key5 invisible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't3'::regclass order by indkey;
|
||||||
|
|
||||||
|
create table t4 (a int, b int);
|
||||||
|
create index key6 on t4(a) invisible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't4'::regclass order by indkey;
|
||||||
|
alter index key6 visible;
|
||||||
|
select indkey, indisvisible from pg_index where indrelid = 't4'::regclass order by indkey;
|
||||||
|
|
||||||
insert into t1 values (generate_series(1, 100), generate_series(1, 100));
|
insert into t1 values (generate_series(1, 100), generate_series(1, 100));
|
||||||
analyze t1;
|
analyze t1;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user