1.MySQL索引类型
-
主键索引
-
普通索引
-
唯一索引
-
全文索引
-
复合索引
2.复合索引最左原则
如上图表counrty建立了一个idx_name_population(Name,population);则支持 Name | Name,population两种组合查询;
测试结果如下:
1.type=all未使用索引
2. type=ref 使用了索引
3.type=ref 使用了索引
3.关于like何时触发索引
like搜索中 %在最前则不触发索引;
1.type=ALL
2.type=range
4.主键查询时是const
以上测试可以发现 type 有all /range /ref /const 几种类型 :
引述 https://www.cnblogs.com/clphp/p/5403215.html
结果值从好到坏依次是:
system > const > eq_ref > ref > fulltext > ref_or_null > index_merge > unique_subquery > index_subquery > range > index > ALL
一般来说,得保证查询至少达到range级别,最好能达到ref,否则就可能会出现性能问题。