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

openGauss每日一练第9天 | (学习内容/心得体会)

原创 四宝 2021-12-16
187

学习openGauss普通表索引

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

1. 创建索引 字段上创建普通的唯一索引

create table products(id int,name char(30));

 

alter table products add (shenfen char(30));

create unique index products_id_index1 on products(id);

 

字段上创建指定B-tree索引

create unique index products_name_index2 on products using btree(name);

 

字段上创建表达式索引。

 create index product_shenfen_index3 on products(substr(shenfen,1,4));

–查看表信息

\d+ products

–查看系统视图pg_indexes

 

2. 修改索引

–重命名索引定义

alter index product_shenfen_index3 rename to products_shenfen_index3;

 

–设置索引不可用

alter index products_id_index1 unusable;

–修改索引表空间

alter index products_name_index2 set tablespace tbs1;

 

3.重建索引

–重建一个单独索引

ALTER INDEX products_id_index1  REBUILD;

或者

REINDEX INDEX products_id_index1;

–重建所有索引

reindex table products;

 

3. 删除索引

Drop index indexname;

 

 

 

 

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

评论