学习目标
学习openGauss普通表索引
索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息
准备工作
启动数据库
su - omm gsql -r
复制
课程作业
1. 创建表products, 分别为表创建一个unique索引1,指定b-tree索引2和表达式索引3
create table products(
id int,
name char(20));
create unique index index1 on products(id);
create index index2 on products using btree(id);
create index index3 on products(substr(name,1,4));
复制
2. 设置索引1不可用,修改索引2的表空间,重命名索引3
alter index index1 unusable;
create tablespace example0 relative location 'tablespace1/tablespace_0';
alter index index2 set tablespace example0;
alter index index3 rename to index30;
复制
使用 \d+ products命令查看表上的index信息
索引各项操作成功!!
3. 重建索引2和products的所有索引
alter index index2 rebuild;
reindex table products;
复制
4. 使用\d+和系统视图pg_indexes查看索引信息
select * from pg_indexes where tablename='products';
复制
5. 删除索引、表和表空间
drop index index1;
drop index index2;
drop index index3;
drop table products;
drop tablespace if exists example0;
复制
课程总结
Day9:学习了openGauss里对于索引的各项操作,并且结合之前学习的表空间知识,修改索引的表空间。
Day9 打卡 get√
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
2025年3月国产数据库大事记
墨天轮编辑部
869次阅读
2025-04-03 15:21:16
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
MogDB
286次阅读
2025-04-17 10:41:41
openGauss 7.0.0-RC1 版本正式发布!
Gauss松鼠会
199次阅读
2025-04-01 12:27:03
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
云和恩墨
183次阅读
2025-04-16 09:52:02
openGauss 7.0.0-RC1 版本体验:一主一备快速安装指南
孙莹
175次阅读
2025-04-01 10:30:07
鲲鹏RAG一体机解决方案正式发布 openGauss DataVec向量数据库助力DeepSeek行业应用
Gauss松鼠会
122次阅读
2025-03-31 10:00:29
荣誉时刻!openGauss认证证书快递已发,快来看看谁榜上有名!
墨天轮小教习
105次阅读
2025-04-23 17:39:13
openGauss6.0.0适配操作系统自带的软件,不依赖三方库
来杯拿铁
75次阅读
2025-04-18 10:49:53
opengauss使用gs_probackup进行增量备份恢复
进击的CJR
70次阅读
2025-04-09 16:11:58
Postgresql数据库单个Page最多存储多少行数据
maozicb
54次阅读
2025-04-23 16:02:19