前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Mysql explain-type使用详解

Mysql explain-type使用详解

作者头像
全栈程序员站长
发布2022-11-02 11:00:09
3130
发布2022-11-02 11:00:09
举报
文章被收录于专栏:全栈程序员必看

下面是测试用例,楼主的测试使用的MySQL版本是5.6.27-log。

show create table user_man;

CREATE TABLE `user_man` ( `manid` bigint(20) NOT NULL AUTO_INCREMENT, `manname` varchar(32) DEFAULT NULL, `manage` int(6) DEFAULT NULL, `upd_time` timestamp NOT NULL DEFAULT ‘2000-01-01 00:00:00’ ON UPDATE CURRENT_TIMESTAMP, `blacklist` bigint(20) DEFAULT ‘-1’ COMMENT ‘-1,1’, PRIMARY KEY (`manid`), KEY `IDX_MN` (`manname`) USING BTREE, KEY `IDX_MID` (`manid`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;

show create table user_woman; CREATE TABLE `user_woman` ( `womanid` int(11) NOT NULL AUTO_INCREMENT, `womanname` varchar(20) DEFAULT NULL, `womanage` int(6) DEFAULT NULL, PRIMARY KEY (`womanid`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

#执行计划中type定义说明:

#(1)执行计划type为ALL:遍历全表来查找 explain SELECT * from user_man ; explain select * from user_man where manage in (9,10);#非索引范围查找也是走全表

#(2)执行计划type为index:只遍历索引树 explain SELECT manid from user_man;

#(3)执行计划type为range:索引扫描范围 explain select *from user_man where manid < 10; explain select * from user_man where manid in (8,10,9) order by manage;

#(4)执行计划type为ref:非唯一性扫描索引 explain select *from user_man where manname = ‘zzk’;

#(5) 执行计划type为eq_ref:唯一性索引扫描 explain select * from user_man ,user_woman where user_man.manid = user_woman.womanid; explain select * from user_man where manid in (select womanid from user_woman);

#(6)执行计划type为const、system:当MySQL对查询某部分进行优化,并转换为一个常量时,使用这些类型访问。如将主键置于where列表中,MySQL就能将该查询转换为一个常量 explain select *from user_man where manid = 8; explain select * from (select * from user_man where manid=8) dd;

#(7)NULL:MySQL在优化过程中分解语句,执行时甚至不用访问表或索引 explain select * from user_man where manid = (select min(womanid) from user_woman)

#查询中若使用了覆盖索引,则该索引仅出现在key列表中(为manid、manname建立了索引,单独查这两个字段); explain select manid ,manname from user_man where manname = ‘zzzz’ and manage = 43;

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/180940.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年10月17日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档