学习目标
掌握openGauss DBMS索引的管理:创建索引、删除索引、查询索引的信息、修改索引的信息。
课程作业
1.创建表,在表中创建索引
为表test的testnum列创建一个索引
create table test(id serial primary key,testnum serial);
create index idx_test_testnum on test(testnum);
查看索引
\di
2.通过hint使用索引
EXPLAIN SELECT /*+ indexscan(test idx_test_testnum ) */ * from test where id<100;

3.rename索引
alter index idx_test_testnum rename to idx_test_testnum_new;
4.重建索引
重建一个单独索引
alter index idx_test_testnum_new rebuild;
reindex index idx_test_testnum_new;
重建test表上所有索引
reindex table test;
5.移动索引到其他表空间
创建表空间 myindex_ts:
create tablespace myindex_ts relative location 'tablespace/myindex_ts1';
将索引idx_test_testnum_new移动到表空间myindex_ts
alter index idx_test_testnum_new set tablespace myindex_ts;
--查看索引所在的表空间
select * from pg_indexes
where 1=1
--and tablename = 'test'
and indexname = 'idx_test_testnum_new';

6.删除索引
drop index idx_test_testnum_new;




