暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第17天 |openGauss逻辑结构:索引管理

原创 bingo_007 2022-12-10
282

学习目标

掌握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;



「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论