您好,欢迎访问一九零五行业门户网

mysql优化必备explain关键字_MySQL

mysqlexplain
一.语法
explain select sid,filename,filetype from (select * from by_disk_file where uid=830814) a
结果:
id:sql执行顺序标示,sql是从大到小执行的
select_type:为查询类型,有以下几种:
1.simple
简单select(不使用union或子查询等)
例如:
explain select * from by_disk_file where uid=830814
2.primary
最外层的查询操作
例如:
explain select * from (select * from by_disk_file where uid=830814 )
3.union
union中的第二个或后面的select语句
例如:
explain select * from by_disk_file where uid=830814 union all select * from by_disk_file
4.dependent union
union中的第二个或后面的select语句,取决于外面的查询
例如:
explain select * from by_disk_file where uid in(select id from by_common_member where username='mm' union all select id from by_common_member where username='gg')
5.union result
union的结果
例如:
explain select * from by_disk_file where uid=830814 union all select * from by_disk_file union all select * from by_disk_file where uid=830814
union查询的步骤(根据以上内容):
定义一个union结果集->union获得语句(从右到左)->第一条语句->结果全获取返回
6.subquery
子查询中的第一个查询
explain select * from by_disk_file where uid=(select uid from by_common_member where username='mm')
7.dependent subquery
子查询中的一个查询,取决于外面的查询
explain select * from by_disk_file where sid in (select sid from by_disk_file where uid=830814)
explain select * from by_disk_file where sid =(select sid from by_disk_file where uid=830814 limit 1)
备注:如果外面的查询不是范围查询只会被查到一次,则为subquery
如果是使用in类似的范围查询,则为dependent subquery
8.derived
派生表的查询(from子句的子查询)
explain select sid,filename,filetype from (select * from by_disk_file where uid=830814) a
其它类似信息

推荐信息