美文网首页
mysql索引部分(一)索引基础

mysql索引部分(一)索引基础

作者: nhsf | 来源:发表于2018-11-23 01:01 被阅读0次

创建索引-alter table 表名 索引类型 索引名(字段)

创建唯一索引

  • alter table 表名 add unqiue index 索引名 on 表名(字段)

创建复合索引

  • alter table 表名 add index 索引名 on 表名(字段1,字段2....)

sql语句执行顺序

  • from ..on..join..group..having..select (dinstinct)..order by limit...

删除索引

  • drop index 索引名 on 表名

查询索引

  • show index on 表名

MySQL中explain的type类型

| ALL | 全表扫描
| index | 索引全扫描
| range | 索引范围扫描,常用语<,<=,>=,between等操作
| ref | 使用非唯一索引扫描或唯一索引前缀扫描,返回单条记录,常出现在关联查询中
| eq_ref | 类似ref,区别在于使用的是唯一索引,使用主键的关联查询
| const/system | 单条记录,系统会把匹配行中的其他列作为常数处理,如主键或唯一索引查询
| null | MySQL不访问任何表或索引,直接返回结果

相关文章

网友评论

      本文标题:mysql索引部分(一)索引基础

      本文链接:https://www.haomeiwen.com/subject/fakdqqtx.html