MySQL Explain

程序员 2024-9-20 11:32:50 97 0 来自 中国
mysql执行计划

在日常工作中,为了知道优化SQL语句的执行,需要查看SQL语句的具体执行过程,以加快SQL语句的执行效率。
可以使用explain+SQL语句来模拟优化器执行SQL查询语句,从而知道mysql是如何处理sql语句的。
官网地址: https://dev.mysql.com/doc/refman/5.5/en/explain-output.html
1、执行计划中包含的信息

ColumnMeaningidThe SELECT identifierselect_typeThe SELECT typetableThe table for the output rowpartitionsThe matching partitionstypeThe join typepossible_keysThe possible indexes to choosekeyThe index actually chosenkey_lenThe length of the chosen keyrefThe columns compared to the indexrowsEstimate of rows to be examinedfilteredPercentage of rows filtered by table conditionextraAdditional informationid

select查询的序列号,包含一组数字,表示查询中执行select子句或者操作表的顺序
id号分为三种情况:
1、如果id相同,那么执行顺序从上到下
2、如果id不同,如果是子查询,id的序号会递增,id值越大优先级越高,越先被执行
3、id相同和不同的,同时存在:相同的可以认为是一组,从上往下顺序执行,在所有组中,id值越大,优先级越高,越先执行
select_type

主要用来分辨查询的类型,是普通查询还是联合查询还是子查询
select_type ValueMeaning解释SIMPLESimple SELECT (not using UNION or subqueries)SIMPLE(简单SELECT,不使用UNION或子查询等)PRIMARYOutermost SELECT查询中若包含任何复杂的子部分,最外层的select被标记为PRIMARY)UNIONSecond or later SELECT statement in a UNIONUNION中的第二个或后面的SELECT语句)DEPENDENT UNIONSecond or later SELECT statement in a UNION, dependent on outer queryUNION中的第二个或后面的SELECT语句,取决于外面的查询UNION RESULTResult of a UNION.UNION的结果SUBQUERYFirst SELECT in subquery子查询中的第一个SELECTDEPENDENT SUBQUERYFirst SELECT in subquery, dependent on outer query子查询中的第一个SELECT,取决于外面的查询DERIVEDDerived table派生表的SELECT, FROM子句的子查询UNCACHEABLE SUBQUERYA subquery for which the result cannot be cached and must be re-evaluated for each row of the outer query一个子查询的结果不能被缓存,必须重新评估外链接的第一行UNCACHEABLE UNIONThe second or later select in a UNION that belongs to an uncacheable subquery (see UNCACHEABLE SUBQUERY)
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-18 16:55, Processed in 0.140039 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表