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

openGauss每日一练第10天 | 分区表索引的基本管理

原创 Lucifer三思而后行 2021-12-10
608

openGauss 每日一练第 10 天打卡,我来了!又可以学习,真开心~

学习

今天第 10 课,学习openGauss分区表索引!

索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息。

课后作业打卡

1.创建范围分区表products, 为表创建分区表索引1,不指定索引分区的名称,创建分区表索引2,并指定索引分区的名称,创建GLOBAL分区索引3

--创建分区表 products CREATE TABLE products ( id int, name CHAR(20) ) partition by range (id) ( partition products_p0 values less than (50), partition products_p1 values less than (100), partition products_p2 values less than (150), partition products_p3 values less than (200), partition products_p4 values less than (250) );

-- 创建分区表索引1 create index products_p1_index1 ON products(id) LOCAL; -- 创建分区表索引2 create index products_p1_index2 ON products(id) LOCAL ( PARTITION id_index1, PARTITION id_index2 TABLESPACE example3, PARTITION id_index3 TABLESPACE example4, PARTITION id_index4 TABLESPACE example3, PARTITION id_index5 TABLESPACE example4 ); -- 创建GLOBAL分区索引3 create index products_p1_index3 ON products(name) GLOBAL;

2.在分区表索引1上,修改分区表索引的表空间,重命名分区表索引

alter index products_p1_index2 move partition id_index1 tablespace example3; alter index products_p1_index2 rename partition id_index1 to id_index0;

3.在分区表索引1上,重建单个索引分区和分区上的所有索引

reindex index products_p1_index1 partition products_p1_id_idx; reindex index products_p1_index1; reindex table products partition products_p0;

4.使用\d+、系统视图pg_indexes和pg_partition查看索引信息

\d+ products select * from pg_indexes where tablename = 'products'; select * from pg_partition;

5.删除索引、表和表空间

drop index products_p1_index1; drop index products_p1_index2; drop index products_p1_index3;

写在最后

今天的作业打卡结束!🎉

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

文章被以下合辑收录

评论