学习目标
学习openGauss普通表索引
索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息
课程作业
1.创建表products, 分别为表创建一个unique索引1,指定b-tree索引2和表达式索引3
SQL:create table products (pd_id int,
pd_name varchar(30),
pd_desc varchar(100),
pd_type char(30));
create unique index ds_pd_id_index1 on products(pd_id);
create index ds_pd_name_index2 on products using btree(pd_name);
create index ds_pd_type_index3 on products(pd_type);
create index ds_pd_desc_index4 on products(pd_desc);
截图展示:
2.设置索引1不可用,修改索引2的表空间,重命名索引3
SQL:
alter index ds_pd_id_index1 unusable;
alter index ds_pd_name_index2 set tablespace example0;
alter index ds_pd_type_index3 rename to ds_pd_type_index3_1;
截图展示:
3.重建索引2和products的所有索引
SQL:
alter index ds_pd_name_index2 rebuild;
reindex table products;
截图展示:
4.使用\d+和系统视图pg_indexes查看索引信息
SQL:
\d+ products
select * from pg_indexes where tablename='products';
截图展示:
5.删除索引、表和表空间
SQL:
drop index ds_pd_id_index1;
drop index ds_pd_name_index2;
drop index ds_pd_type_index3_1;
drop table products;
drop tablespace example0;
截图展示:
今天学习数据库的索引的建立删除重命名,查看索引空间;自己操作不熟练很多次都命令敲错了,在以后的学习过程中不要再犯类似的错误;