MySql--索引


索引
注意
要注意的是,建立太多的索引将会影响更新和插入的速度,因为它需要同样更新每个索引文件。
对于一个经常需要更新和插入的表格,就没有必要为一个很少使用的where字句单独建立索引了,
对于比较小的表,排序的开销不会很大,也没有必要建立另外的索引。

建立索引会占用磁盘空间


 索引最主要解决的问题

-- 当数据非常庞大时,并且这些数据不需要经常修改,为了加快查询速度,我们会使用索引

 创建一张表
create table test_index(title varchar(10));

--测试步骤
1. 开启运行时间监测:
set profiling=1;
2. 查找第1万条数据ha-99999
select * from test_index where title='ha-99999';
3. 查看执行的时间:
show profiles;
4. 为表title_index的title列创建索引:
create index 索引名称 on 表名(字段名称)

create index my_index on test_index(title);
5. 执行查询语句:
select * from test_index where title='ha-99999';
6. 再次查看执行的时间
show profiles;

--查看索引
-- show index from 表名;
show index from test_index;

--删除索引

---drop index 索引名 on 表名;
drop index my_index on test_index;


猜你喜欢

转载自blog.csdn.net/qq_38792622/article/details/80219116