mysql 索引type介绍
<div id="article_content" class="article_content clearfix"><link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
<link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
<div id="content_views" class="htmledit_views">
<p><strong>以下全部详细解析explain各个属性含义:</strong></p>
<p> </p>
<p style="text-align:center;"></p>
<p></p>
<p> <strong>各属性含义:</strong><br> <strong>id:</strong> 查询的序列号<br> <strong>select_type:</strong> 查询的类型,主要是区别普通查询和联合查询、子查询之类的复杂查询</p>
<ul><li><code>SIMPLE</code>:查询中不包含子查询或者<code>UNION</code></li><li>查询中若包含任何复杂的子部分,最外层查询则被标记为:<code>PRIMARY</code></li><li>在<code>SELECT</code>或<code>WHERE</code>列表中包含了子查询,该子查询被标记为:<code>SUBQUERY</code></li></ul>
<p> <strong>table:</strong> 输出的行所引用的表<br> <strong>type:</strong> 访问类型<br> </p>
<p style="text-align:center;"></p>
<p></p>
<p> <strong>从左至右,性能由差到好</strong></p>
<ol><li>ALL: 扫描全表</li><li>index: 扫描全部索引树</li><li>range: 扫描部分索引,索引范围扫描,对索引的扫描开始于某一点,返回匹配值域的行,常见于between、<、>等的查询</li><li>ref: 使用非唯一索引或非唯一索引前缀进行的查找<br><strong>(<code>eq_ref和const的区别:</code>)</strong></li><li><code>eq_ref:唯一性索引扫描,对于每个索引键,表中只有一条记录与之匹配。常见于主键或唯一索引扫描</code></li><li><code>const, system: 单表中最多有一个匹配行,查询起来非常迅速,例如根据主键或唯一索引查询。system是const类型的特例,当查询的表只有一行的情况下, 使用system。</code></li><li>NULL: 不用访问表或者索引,直接就能得到结果,如<code>select 1 from test where 1</code></li></ol>
<p> <strong>possible_keys: </strong>表示查询时可能使用的索引。如果是空的,没有相关的索引。这时要提高性能,可通过检验WHERE子句,看是否引用某些字段,或者检查字段不是适合索引</p>
<p> <strong>key: </strong>显示MySQL实际决定使用的索引。如果没有索引被选择,是NULL</p>
<p> <strong>key_len: </strong>使用到索引字段的长度</p>
<p> 注:key_len显示的值为索引字段的最大可能长度,并非实际使用长度,即key_len是根据表定义计算而得,不是通过表内检索出的。</p>
<p> <strong>ref: </strong>显示哪个字段或常数与key一起被使用</p>
<p> <strong>rows: </strong>这个数表示mysql要遍历多少数据才能找到,表示MySQL根据表统计信息及索引选用情况,估算的找到所需的记录所需要读取的行数,在innodb上可能是不准确的</p>
<p> <strong>Extra: </strong>执行情况的说明和描述。包含不适合在其他列中显示但十分重要的额外信息。</p>
<ol><li>
<ol><li>Using index:表示使用索引,如果只有 Using index,说明他没有查询到数据表,只用索引表就完成了这个查询,这个叫覆盖索引。</li><li>Using where:表示条件查询,如果不读取表的所有数据,或不是仅仅通过索引就可以获取所有需要的数据,则会出现 Using where。</li></ol></li></ol>
</div>
</div>
<div id="treeSkill"></div>
页:
[1]