对mysql使用索引的误解 – 小松博客

以前我一直觉得mysql一个查询中只能使用一个索引,网上的资料有这个说的,并且我也觉得是这样的,结果今天发现错了php

主要是在验证只使用一个索引的时候发现,key中显示了两个索引字段,type中显示index_merge
如图html

mysql explain

若是按照以前的理解只使用个索引,那就有问题了,那为何有人会说只使用一个索引mysql

答案在这里版本问题sql

MySQL5.0以前,一个表一次只能使用一个索引,没法同时使用多个索引分别进行条件扫描,可是从5.1开始,引入了 index merge 优化技术,对同一个表能够使用多个索引分别进行条件扫描app

不能在相信百度里的资料了,查官方文档
官方文档:  http://dev.mysql.com/doc/refman/5.7/en/index-merge-optimization.html优化

The Index Merge method is used to retrieve rows with several range scans and to merge their results into one. The merge can produce unions, intersections, or unions-of-intersections of its underlying scans. This access method merges index scans from a single table; it does not merge scans across multiple tables.this

索引合并方法用于与几个范围扫描检索行和他们的结果合并为一个。合并分为union, intersection, 以及它们的组合(先内部intersect而后在外面union)。这种访问方式合并来自单个表索引扫描;它不合并跨多个表扫描。htm

In EXPLAIN output, the Index Merge method appears as index_merge in the type column. In this case, the key column contains a list of indexes used, and key_len contains a list of the longest key parts for those indexes.blog

在EXPLAIN输出,索引合并方法出如今类型列index_merge。在这种状况下,键列包含用于索引的列表,而且key_len包含这些索引的最长键部件的列表索引

说的够明白了
参考: http://www.cnblogs.com/digdeep/archive/2015/11/18/4975977.html

QQ交流群:136351212(满) 455721967

如无特别说明,本站文章皆为原创,若要转载,务必请注明如下原文信息:
转载保留版权:小松博客» 对mysql使用索引的误解
本文连接地址:https://www.phpsong.com/2753.html

相关文章
相关标签/搜索