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

openGauss每日一练第十天 | 分区表索引

原创 护苗使者9G 2021-12-10
1313

学习目标

学习openGauss分区表索引

课程学习

连接数据库

su - omm
gsql -r

企业微信截图_16391408435033.png

课程作业

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

CREATE TABLESPACE ex1 RELATIVE LOCATION 'tablespace1/ex1';
CREATE TABLESPACE ex2 RELATIVE LOCATION 'tablespace2/ex2';
CREATE TABLESPACE ex3 RELATIVE LOCATION 'tablespace3/ex3';
CREATE TABLESPACE ex4 RELATIVE LOCATION 'tablespace3/ex4';
create schema anson;
create table anson.products
(
     id int not null,
     name char(20),
     type char(20),
     local char(30)
 )     
partition by range (id)
(
        partition stp0 values less than (1000) tablespace ex1,
        partition stp1 values less than (5000) tablespace ex2,
        partition stp2 values less than (MAXVALUE) tablespace ex3
);
create index pro_id_index1 ON anson.products(id) local;
create index pro_id_index2 on anson.products(id) local(
partition p_id_1 tablespace ex1,
partition p_id_2 tablespace ex2,
partition p_id_3 tablespace ex3
);
create index pro_name_index3 on anson.products(name) global;

企业微信截图_16391412117025.png

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

alter index anson.pro_id_index1 set tablespace ex4; #报错无法移动,只能移分区表  
\d+ anson.products; 查看表信息
alter index anson.pro_id_index1 move partition stp0_id_idx tablespace ex4;
alter index anson.pro_id_index1 rename to pro_id_index10;

企业微信截图_16391418945219.png

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

reindex index anson.pro_id_index2 partition p_id_1;
reindex index anson.pro_id_index2;
reindex table anson.products partition stp0;

企业微信截图_16391427151889.png

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

\d+ anson.products;
select * from pg_indexes where schemaname='anson' and tablename = 'products';

企业微信截图_16391428212746.png

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

drop index anson.pro_id_index10;
drop index anson.pro_id_index2;
drop index anson.pro_name_index3;
drop table anson.products;
drop tablespace ex1;
drop tablespace ex2;
drop tablespace ex3;
drop tablespace ex4;

企业微信截图_16391431121952.png

学习在于坚持,今天又愉快的结束了,学了openGauss数据库分区表索引相关的操作,缺乏索引或者错误的索引会直接影响系统的性能,课程的内容也逐渐加深,让我们能连贯复习前面几节课程的内容,期待继续学习,更加了解openGauss数据库,同时知悉各数据库的异同之处,能顺畅的使用openGauss数据库。

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

评论