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

openGauss每日一练第 9 天 |学习openGauss普通表索引

原创 黄超 2021-12-14
387

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

1.创建表products, 分别为表创建一个unique索引1,指定b-tree索引2和表达式索引3

create schema hc;
create table hc.products
(product_id INTEGER,
product_name Char(30),
category Char(20)
);
create unique index products_idx1 on hc.products(product_id);
create index products_idx2 on hc.products USING btree(product_id);
create index products_idx3 on hc.products (SUBSTR(product_name,1 ,4));
9_1.png

2.设置索引1不可用,修改索引2的表空间,重命名索引3

ALTER INDEX hc.products_idx1 UNUSABLE;
CREATE TABLESPACE tspc1 RELATIVE LOCATION ‘tablespace/tablespace_1’;
alter index hc.products_idx2 set tablespace tspc1;
alter index hc.products_idx3 rename to products_idx300;
9_2.png

3.重建索引2和products的所有索引

reindex index hc.products_idx2;
reindex table hc.products;
9_3.png

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

\d+ hc.products
select * from pg_indexes where tablename = ‘products’;
9_4.png

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

drop index hc.products_idx1;
drop index hc.products_idx2;
drop index hc.products_idx300;
drop table hc.products;
drop schema hc;
drop tablespace tspc1;
9_5.png

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

文章被以下合辑收录

评论