`

Mysql Using where using index

 
阅读更多

Mysql 的执行计划中有项不起眼但同时很让人产生误解的东西,其中有一项就是Extra, 这一列放在了最后,并且意思是额外的辅助信息,似乎是最不起眼的一个项。

 

Column JSON Name Meaning
id select_id The SELECT identifier
select_type None The SELECT type
table table_name The table for the output row
partitions partitions The matching partitions
type access_type The join type
possible_keys possible_keys The possible indexes to choose
key key The index actually chosen
key_len key_length The length of the chosen key
ref ref The columns compared to the index
rows rows Estimate of rows to be examined
filtered filtered Percentage of rows filtered by table condition
Extra None Additional information

 

 EXPLAIN Extra Information

Extra会有哪些值呢? 官方列出了20多种,我一一看了下,大部分都是特别好懂,有兴趣可以点击上面链接去官网查看,我不在一一详列。 其中最常见的莫过于以下几种了。

Using index (JSON: using_index)

The column information is retrieved from the table using only information in the index tree without having to do an additional seek to read the actual row. This strategy can be used when the query uses only columns that are part of a single index. (这个用一句话解释,就是覆盖索引,不需要读取数据文件)

 例如:

语句1:select id from T where id =1;(id 为primary key)

可是如果将查询改为:

 alter table T add index idx_name('name');

 语句2: select name from t where name='test';

Extra就会变为 Using where; Using index

 

为什么呢?很明显语句2也是走索引查询,也是覆盖索引。我们来看看官方的E文

 

Using where (JSON: attached_condition text)

WHERE clause is used to restrict which rows to match against the next table or send to the client. Unless you specifically intend to fetch or examine all rows from the table, you may have something wrong in your query if the Extra value is not Using where and the table join type is ALL or index.

 

join type 是 ALL 或者 index都是走全表扫描,只是一个扫表,一个扫索引。 那么Using where 的意思在这里似乎也解释的很明朗,那就是用来过滤的。 可是为什么语句1 没有用Using where呢? 其实我认为这只是一个理解的问题。 并不代表语句一没有用where去过滤定位, 而是唯一索引可以一次性定位出固定的值,而非唯一索引只能找到索引的页码,具体的值还得根据Where条件继续去遍历索引。

 

File sort: 并不代表文件排序

这两个定义确实很容易给人造成误解,所以我的建议是不要在这两个信息里面做过多的想像。前面的项目信息更有参考价值。

 

分享到:
评论

相关推荐

    MySQL数据库:USING子句.pptx

    表名1 INNER JOIN 表名2 USING (列名) [WHERE 条件表达式] 外连接语法格式如下: 表名1 LEFT| RIGHT JOIN 表名2 USING (列名) [WHERE 条件表达式] ; 【例】 查找Members表中所有订购过图书的会员的姓名。 SELECT ...

    mysql数据库的基本操作语法

    MySQL结束符是“;”结束。 1、 显示所有数据库 show databases; 2、 删除数据库 drop database dbName; 3、 创建数据库 create database [if not exists] dbName; 中括号部分可选的,判断该数据不存在就创建 4、 ...

    【mysql知识点整理】— order by 、group by 出现Using filesort原因详解

    理论3 order by 和 group by什么时候会出现Using filesort — 实践3.1 不会出现 Using filesort的情况 — 符合最佳左前缀法则3.1.1 order by也满足索引最佳左前缀法则的时候3.1.2 where中索引的最左前缀定义为常量的...

    MySQL8.0文档(英文)

    For help with using MySQL, please visit either the MySQL Forums or MySQL Mailing Lists, where you can discuss your issues with other MySQL users. Document generated on: 2018-05-11 (revision: 57346)

    MySQL中USING 和 HAVING 用法实例简析

    本文实例讲述了MySQL中USING 和 HAVING 用法。分享给大家供大家参考,具体如下: USING 用于表连接时给定连接条件(可以理解为简写形式),如 SELECT * FROM table1 JOIN table2 ON table1.id = table2.id 使用 ...

    linux安装mysql(rpm脱网安装).zip

    mysql> update user set password=password('123456') where user='root'; mysql> update user set host = '%' where user = 'root'; mysql> flush privileges; 错误解决: You must reset your password using ...

    Explain详解及SQL优化实战.docx

    Mysql数据库优化实战,里面有一些小的例子来说明执行计划的讲解。

    mysql-5.7.17-winx64.zip 解压版

    然后我们使用show databases查看所有数据库,这个时候如果提示:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 我们就输入 set password=...

    SQL导出MySQL单个存储过程.txt

    SQL语句对单个的MySQL存储过程导出 首先确保参数secure-file-priv='' 表示...') USING UTF8) STORE FROM MYSQL.PROC A WHERE A.NAME = PRO_NAME INTO OUTFILE "/HOME/MYSQL/PRO_NAME.SQL" FIELDS ESCAPED BY '';

    mysql常见错误汇总

    ERROR 1045 (28000): Access denied for user *** (using password: YES ERROR 1054 (42S22): Unknown column *** in 'where clause' ERROR 1064 (42000): You have an error in your SQL syntax; ERROR 1072 ...

    mysql-cluster-excerpt-5.7-en.a4.pdf

    MySQL Cluster NDB 7.5: ...For help with using MySQL, please visit the MySQL Forums, where you can discuss your issues with other MySQL users. Document generated on: 2020-05-22 (revision: 66080)

    MySQL8.0中的降序索引

    不过,在MySQL之前版本中,只支持升序索引,不支持降序索引,这会带来一些问题;在最新的MySQL 8.0版本中,终于引入了降序索引,接下来我们就来看一看。 降序索引 单列索引 (1)查看测试表结构 mysql> show ...

    ERROR CODE: 1175 YOU ARE USING SAFE UPDATE MODE AN

    You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column 进过一番搜索之后发现原来是MySQL Workbench的安全设置。当要执行的SQL语句是进行批量更新或者删除的时候...

    MySQL Connector/J 5.1 Developer Guide

    This manual describes how to install, configure, and develop database applications ...For help with using MySQL, please visit either the MySQL Forums or MySQL Mailing Lists, where you can discuss your

    MySQL中基本的多表连接查询教程

     由于其返回的结果为被连接的两个数据表的乘积,因此当有WHERE, ON或USING条件的时候一般不建议使用,因为当数据表项目太多的时候,会非常慢。一般使用LEFT [OUTER] JOIN或者RIGHT [OUTER] JOIN  2. 内连接INNER ...

    High Performance MySQL

    using it more and more in applications that are exposed to the Internet, where down- time and other problems cannot be concealed or tolerated. As a result, this second edition has a slightly different...

    socket身份校验(存储过程)mysql数据库

    服务器端导入MySql.Data.dll包并using MySql.Data.MySqlClient; 用mysql的存储过程查询表中的数据 mysql数据库 tb_users表 use test; DROP TABLE IF EXISTS tb_users; CREATE TABLE IF NOT EXISTS tb_users ( id ...

    MySQL数据库:数据记录的删除.pptx

    [WHERE 条件] 说明: ● 如果省略WHERE子句则删除该表的所有行。 【例】 将book中书名为“PHP网站制作”的记录删除。 DELETE FROM book WHERE 书名='PHP网站制作'; ;使用DELETE语句删除多表数据 从多个表中删除行,...

    Mysql 关键字执行顺序

    Mysql 会先执行 from,然后根据 on 关键字去筛选目标表,筛选出的结果再进行 join 或者 using,这样就会形成一个临时表。然后去执行 where 条件去筛选这个临时表,这样基本就 筛选出需要的数据了。

    ERROR 1045 (28000): Access denied for user ”root”@”localhost” (using password: YES)实用解决方案

    昨天连数据库没有问题,但是今天连接数据库就报这个错误了,网上也搜了不少的方法,有一个方法解决了我的问题。我的环境是Linux ...mysql> update user set password=password("你的新密码") where user="root"; m

Global site tag (gtag.js) - Google Analytics