explain是mysql的关键字吗_mysql优化必备explain关键字_MySQL

MySQLexplain

一.语法EXPLAIN select sid,filename,filetype from (SELECT * from by_disk_file where uid=830814) a

结果:

mysql-tutorials-65922.html

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

mysql-tutorials-65922.html

UNION查询的步骤(根据以上内容):

定义一个UNION结果集->UNION获得语句(从右到左)->第一条语句->结果全获取返回

6.SUBQUERY

子查询中的第一个查询explain select * from by_disk_file where uid=(select uid from by_common_member where username='mm')

mysql-tutorials-65922.html

7.DEPENDENT SUBQUERY

子查询中的一个查询,取决于外面的查询explain select * from by_disk_file where sid in (select sid from by_disk_file where uid=830814)

mysql-tutorials-65922.html

explain select * from by_disk_file where sid =(select sid from by_disk_file where uid=830814 LIMIT 1)

mysql-tutorials-65922.html

备注:如果外面的查询不是范围查询只会被查到一次,则为SUBQUERY

如果是使用in类似的范围查询,则为DEPENDENT SUBQUERY

8.DERIVED

派生表的查询(FROM子句的子查询)explain select sid,filename,filetype from (SELECT * from by_disk_file where uid=830814) a

f68f2add0b68e4f9810432fce46917b7.png

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值