索引
索引含义:单独存储在磁盘上的数据结构,包含数据表所有记录的引用指针。
优点:通过创建唯一索引,可以保护数据可表中每一行数据的唯一性
可以大大加快数据的查询速度(通过索引不需要全表查询了,索引中内容是有序的)
在实现数据的参考完成性方面,可以加速表和表之间的连接
在使用分组和排序子句进行查询时,可以显著减少查询中分组和排序的时间
缺点:创建和维护索引耗费时间
占用磁盘空间
需要动态维护索引,降低数据维护速度
分类:
普通索引和唯一索引
单列索引和组合索引
扫描二维码关注公众号,回复:
889516 查看本文章
全文索引
空间索引
创建索引
查看索引
show index from table_name;
创建表时创建索引
在已经存在的表上创建索引
alter table table_name add [unique/fulltext/spatial] [index/key]
create unique/fulltext/spatial index index_name on table_name (col_name[length]) [asc/desc];
删除索引
alter table table_name drop index index_name;
drop index index_name on table_name;