实验题目:索引重要性、提高速度
实验目的:
对比有无索引情况下数据检索速度,学会如何能够使用索引,掌握如何查询是否使用索引了。
实验原理和方法:
- 按 sid、name 建立两个索引。
create UNIQUE index student_10_sid on student_10(sid)
create index student_10_name on student_10(name) - 对比索引列 sid 和非索引列 sid1 进行查询,观察耗时
select * from pub.student_10 where sid=‘000000020000’,耗时在毫秒级
select * from pub.student_10 where sid1=‘000000020000’, 耗时在 1 秒以上 - 删除索引:drop index xxxx
- 查询用户所有表的索引 :select * from user_indexes
写报告的时候为方便标红(蓝)了,懒得找了,都很简单
实验步骤:
题目 1
1.将pub用户下表student的3个列sid,name,birthday复制到表test7_01中。
2.执行如下查询,观察运行速度(5 秒以上)。
查询 Samefirstname 相同姓氏的人数。
select * from
(select sid,name,birthday,
(select count(*) from test7_01 where substr(name,1,1)=substr(t1.name,1,1)) samefirstname
from pub.student_testindex t1)
where samefirstname=7
为test7_01创建一个仅仅一个索引test7_01_index保证上面 SQL耗时在1秒内。
create table test7_01 as
select sid,name,birthday from pub.student
为姓氏创建索引:create index test7_01_index on test7_01(substr(name,1,