索引
- 定义:类似于图书目录,起到快速检索数据的作用。
- 作用:对于大量数据进行查询效率优化时,可以采取添加索引的策略。
注:主键(primary key)和设置唯一值(unique)都可起索引作用 - 开启时间监测:
set profiling = 1;
查看运行时间:show profiles;
- 索引相关语句
--对已存在的表添加索引
--create index 索引名称 on 表名(字段名);
create index num_index on test_index(num);
--查看索引
--show index from 表名;
show index from test_index;
--创表时添加索引:key(字段名)
create table create_index(
id int primary key,
num varchar(10) unique,
age int,
key(age)
);
--删除索引
--drop index 索引名称 on 表名;
drop