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

openGauss每日一练第 10 天 |学习openGauss分区表索引

原创 黄超 2021-12-15
881

自己安装的openGauss环境
启动openGauss
gs_ctl -D /gauss/data/db1/ start
登录openGauss
gsql -d postgres -p 26000 -r

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

CREATE TABLESPACE example1 RELATIVE LOCATION ‘tablespace1/tablespace_1’;
CREATE TABLESPACE example2 RELATIVE LOCATION ‘tablespace2/tablespace_2’;
CREATE TABLESPACE example3 RELATIVE LOCATION ‘tablespace3/tablespace_3’;
CREATE TABLESPACE example4 RELATIVE LOCATION ‘tablespace4/tablespace_4’;
create schema hc;
create table hc.products
(product_id INTEGER,
product_name Char(30)
)
partition by range (product_id)
(partition p1 values less than (50),PARTITION p2 VALUES LESS THAN (100) TABLESPACE example1,
PARTITION p3 VALUES LESS THAN (MAXVALUE) TABLESPACE example2);

create index products_idx1 on hc.products(product_id) local;
CREATE INDEX products_idx2 ON
hc.products(product_id) LOCAL
(
PARTITION product_id_index1,
PARTITION product_id_index2 TABLESPACE example1,
PARTITION product_id_index3 TABLESPACE example2
);
create index products_idx3 on hc.products(product_name) GLOBAL;
10_1.png

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

ALTER INDEX hc.products_idx2 MOVE PARTITION
product_id_index1 TABLESPACE example1;
ALTER INDEX hc.products_idx2 RENAME PARTITION
product_id_index1 TO product_id_index4;
10_2.png

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

reindex index hc.products_idx2 PARTITION product_id_index4;
reindex table hc.products PARTITION p1;
10_3.png

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

\d+ hc.products;
select * from pg_indexes where tablename = ‘products’;
select * from pg_partition;
10_4_1.png
10_4_2.png
10_4_3.png

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

drop index hc.products_idx1;
drop index hc.products_idx2;
drop index hc.products_idx3;
drop table hc.products;
drop schema hc;
drop tablespace example1;
drop tablespace example2;
drop tablespace example3;
drop tablespace example4;
10_5.png

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

文章被以下合辑收录

评论

黄超
关注
暂无图片
获得了88次点赞
暂无图片
内容获得23次评论
暂无图片
获得了180次收藏
TA的专栏
openGauss专栏
收录25篇内容
MySQL专栏
收录19篇内容
目录
  • 1.创建范围分区表products, 为表创建分区表索引1,不指定索引分区的名称,创建分区表索引2,并指定索引分区的名称,创建GLOBAL分区索引3
  • 2.在分区表索引2上,修改分区表索引的表空间,重命名分区表索引
  • 3.在分区表索引2上,重建单个索引分区和分区上的所有索引
  • 4.使用\d+、系统视图pg_indexes和pg_partition查看索引信息
  • 5.删除索引、表和表空间