14.GaussDB索引的管理

1.GaussDB数据库索引的管理包含以下内容

--索引管理
(1)创建唯一索引,必须指定表的分布键,否则无法成功。
(2)创建复合索引
(3)创建部分索引,只在表的一部分数据上创建索引
(4)创建函数索引
(5)创建分区表的本地索引
(6)创建分区表的全局索引,并指定索引所在的表空间。
(7)索引重命名
(8)修改索引的表空间
(9)让索引不可用
(10)重建索引
(11)重建索引的分区
(12)让索引的某个分区不可用
(13)修改索引分区的名字
(14)移动索引的某个分区到另外的表空间
(15)删除索引
(16)重建表上单个索引
(17)重建表上所有索引

2.GaussDB索引管理具体操作如下

--创建测试数据:
sjzt=> create table t1 as select oid,* from pg_class limit 10;
NOTICE:  The 'DISTRIBUTE BY' clause is not specified. Using 'relallvisible' as the distribution column by default.
HINT:  Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column.
INSERT 0 10
-- 创建唯一索引
--创建索引的时候必须指定分布键,否则无法创建成功。
sjzt=> create unique index t1_fn_idx on t1(relfilenode,relallvisible); 
CREATE INDEX 
-- 创建复合索引
sjzt=> create index t1_owner_tbs_idx on t1(relowner,reltablespace); 
CREATE INDEX
-- 创建部分索引
sjzt=> create index t1_lttbs_idx on t1(reltablespace) where reltablespace<20;
CREATE INDEX
-- 创建函数索引
sjzt=> create index t1_upname_idx on t1(upper(relname)); 
CREATE INDEX
-- 创建分区表的本地索引
sjzt=> create index pt1_id_idx on pt1(id) local; 
CREATE INDEX
-- 创建分区表的全局索引,并指定索引所在的表空间。
sjzt=> create index pt1_score_idx on pt1(score) global tablespace tbs2;
CREATE INDEX 
--索引重命名
sjzt=> alter index t1_fn_idx rename to t1_fn_idx2;
ALTER INDEX
---修改索引的表空间
sjzt=> alter index t1_fn_idx2 set tablespace tbs3;
ALTER INDEX
--让索引不可用
sjzt=> alter index t1_lttbs_idx unusable;
ALTER INDEX
--重建索引。
sjzt=> alter index t1_lttbs_idx rebuild;
REINDEX
--重建索引的分区
sjzt=> alter index pt1_id_idx rebuild partition p1_id_idx;
REINDEX
--让索引的某个分区不可用
sjzt=> alter index pt1_id_idx modify partition p1_id_idx unusable;
ALTER INDEX
--修改索引分区的名字
sjzt=> alter index pt1_id_idx rename partition p1_id_idx to p1_id_idx2;
ALTER INDEX
--移动索引的某个分区到另外的表空间
sjzt=>  alter index pt1_id_idx move partition p1_id_idx2 tablespace tbs3;
ALTER INDEX
--删除索引:
sjzt=> drop index t1_lttbs_idx;
DROP INDEX
-- 重建表上单个索引
sjzt=> reindex index t1_lttbs_idx;
REINDEX
-- 重建表上所有索引
sjzt=> reindex table t1;
REINDEX

3.总结

GaussDB的索引管理,不仅支持我们常见的索引。还支持Reindex关键字,一键重建所有的索引。

索引的管理非常方便,灵活。索引的每个分区都可以独立管理。包括删除,重建,重命名,修改存储表空间等。非常灵活多变

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值