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

openGauss每日一练第17天 | openGauss逻辑结构:索引管理

原创 寒冰 2022-12-10
248

学习目标

掌握openGauss DBMS索引的管理:创建索引、删除索引、查询索引的信息、修改索引的信息。

课程学习

索引是一个指向表中数据的指针。一个数据库中的索引与一本书的索引目录是非常相似的。
索引可以用来提高数据库查询性能,但是不恰当的使用将导致数据库性能下降。  默认的索引是b-tree索引。


课程作业

1.创建表,在表中创建索引

CREATE TABLE jobs (
job_id varchar(10) NOT NULL,
job_title varchar(35) NOT NULL,
min_salary int4 NULL,
max_salary int4 NULL,
CONSTRAINT job_id_pk PRIMARY KEY (job_id)
);


create index jobs_idx on jobs(min_salary);


2.通过hint使用索引

EXPLAIN SELECT /*+ indexscan(customer customer_idx ) */
* FROM jobs WHERE min_salary<100;


这样可以查询出执行计划,可以看到执行的一些信息。

3.rename索引

alter index jobs_idx rename to jobs_idx_new;



4.重建索引

 alter index jobs_idx_new rebuild; --重建单个索引

 reindex index jobs_idx_new;


reindex table jobs;  --重建一个表的所有所有。


 reindex database omm;--重建整个数据库的索引


5.移动索引到其他表空间

create tablespace index_ts relative location 'tablespace/index_ts1';

alter index jobs_idx_new set tablespace index_ts;

 select * from pg_indexes where tablename = 'jobs';



6.删除索引

drop index jobs_idx_new;


两道杠的我继续坚持学习。

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

评论