学习目标
掌握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;

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




