Chinaunix首页
|
论坛
|
博客
博文
博主
onion
4月28日14:30-20:30机房服务器迁移,暂停博客使用
9/30日 14:00 -10/4日 08:00暂时无法发布内容!
9/30日 14:00 -10/4日 08:00暂时无法发布内容!
首页
|
博文目录
|
关于我
bsknight
博客访问: 4139
博文数量: 1
博客积分: 10
博客等级: 民兵
技术积分: 20
用 户 组: 普通用户
注册时间: 2011-02-07 21:51
文章分类
全部博文
(1)
MySQL
(1)
未分配的博文
(0)
文章存档
2014年
(1)
2014年07月
(1)
我的朋友
最近访客
推荐博文
·
ORACLE SQL overlap时间段重...
·
Rust入门到精通(三)—— 不...
·
Oracle 1582-10-07问题
·
1:Python开发:初识Python...
·
ORACLE物理结构
相关博文
·
数据分析查询工具有哪几种类...
·
数据清洗(ETL/ELT)原理是什...
·
中国500强:德力西集团数智...
·
bin$表头的Oracle回收站...
·
图文教程 | 阿里云市场 Serve...
·
长沙岳麓区家具城,全屋软装...
·
MySQL & NaviCat 安装及配置...
·
如何将TPM文化与企业的核心价...
·
两部手机的IP地址:是否会相...
·
小红书怎么隐藏自己的IP归属...
MySQL查询执行计划学习
分类:
Mysql/postgreSQL
2014-07-17 21:46:49
SELECT_TYPE:
1) SIMPLE:简单的SELECT,不实用UNION或者子查询
mysql
>
explain
select
*
from
t2
;
+
----+-------------+-------+------+---------------+------+---------+------+------+-------+
|
id
|
select_type
|
table
|
type
|
possible_keys
|
key
|
key_len
|
ref
|
rows
|
Extra
|
+
----+-------------+-------+------+---------------+------+---------+------+------+-------+
|
1
|
SIMPLE
|
t2
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
100
|
NULL
|
+
----+-------------+-------+------+---------------+------+---------+------+------+-------+
1
row
in
set
(
0
.
00 sec
)
2) PRIMARY:最外层SELECT。
mysql
>
explain
select
*
from
(
select
*
from
t2
where
id2
=
2
)
b
;
+
----+-------------+------------+------+---------------+------+---------+------+------+-------------+
|
id
|
select_type
|
table
|
type
|
possible_keys
|
key
|
key_len
|
ref
|
rows
|
Extra
|
+
----+-------------+------------+------+---------------+------+---------+------+------+-------------+
|
1
|
PRIMARY
|
<
derived2
>
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
100
|
NULL
|
|
2
|
DERIVED
|
t2
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
100
|
Using
where
|
+
----+-------------+------------+------+---------------+------+---------+------+------+-------------+
2
rows
in
set
(
0
.
00 sec
)
3) UNION:第二层,在SELECT之后使用了UNION。
mysql
>
explain
select
*
from
t1
union
select
*
from
t2
;
+
----+--------------+------------+------+---------------+------+---------+------+-------+-----------------+
|
id
|
select_type
|
table
|
type
|
possible_keys
|
key
|
key_len
|
ref
|
rows
|
Extra
|
+
----+--------------+------------+------+---------------+------+---------+------+-------+-----------------+
|
1
|
PRIMARY
|
t1
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
10208
|
NULL
|
|
2
|
UNION
|
t2
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
100
|
NULL
|
|
NULL
|
UNION
RESULT
|
<
union1
,
2
>
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
NULL
|
Using
temporary
|
+
----+--------------+------------+------+---------------+------+---------+------+-------+-----------------+
3
rows
in
set
(
0
.
00 sec
)
4) DEPENDENT UNION:UNION语句中的第二个SELECT,依赖于外部子查询。
mysql
>
explain
select
*
from
t1
where
id1
in
(
select
id2
from
t2
where
id2
<
10
union
select
id3
from
t3
where
id3
<
5
)
;
+
----+--------------------+------------+------+---------------+------+---------+------+-------+--------------------------+
|
id
|
select_type
|
table
|
type
|
possible_keys
|
key
|
key_len
|
ref
|
rows
|
Extra
|
+
----+--------------------+------------+------+---------------+------+---------+------+-------+--------------------------+
|
1
|
PRIMARY
|
t1
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
10208
|
Using
where
|
|
2
|
DEPENDENT SUBQUERY
|
t2
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
100
|
Using
where
|
|
3
|
DEPENDENT
UNION
|
t3
|
ref
|
id3
|
id3
|
5
|
func
|
1
|
Using
where
;
Using
index
|
|
NULL
|
UNION
RESULT
|
<
union2
,
3
>
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
NULL
|
Using
temporary
|
+
----+--------------------+------------+------+---------------+------+---------+------+-------+--------------------------+
4
rows
in
set
(
0
.
00 sec
)
5) UNION RESULT:UNION的结果。
mysql
>
explain
select
*
from
t1
union
select
*
from
t2
;
+
----+--------------+------------+------+---------------+------+---------+------+-------+-----------------+
|
id
|
select_type
|
table
|
type
|
possible_keys
|
key
|
key_len
|
ref
|
rows
|
Extra
|
+
----+--------------+------------+------+---------------+------+---------+------+-------+-----------------+
|
1
|
PRIMARY
|
t1
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
10208
|
NULL
|
|
2
|
UNION
|
t2
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
100
|
NULL
|
|
NULL
|
UNION
RESULT
|
<
union1
,
2
>
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
NULL
|
Using
temporary
|
+
----+--------------+------------+------+---------------+------+---------+------+-------+-----------------+
3
rows
in
set
(
0
.
00 sec
)
6) SUBQUERY:子查询中的第一个SELECT。
mysql
>
explain
select
*
from
t1
where
id1
=
(
select
id2
from
t2
where
id2
=
2
)
;
+
----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
|
id
|
select_type
|
table
|
type
|
possible_keys
|
key
|
key_len
|
ref
|
rows
|
Extra
|
+
----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
|
1
|
PRIMARY
|
t1
|
const
|
PRIMARY
|
PRIMARY
|
4
|
const
|
1
|
NULL
|
|
2
|
SUBQUERY
|
t2
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
100
|
Using
where
|
+
----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
2
rows
in
set
(
0
.
00 sec
)
8) DERIVED:被驱动的SELECT子查询
mysql
>
explain
select
*
from
(
select
*
from
t2
where
id2
=
2
)
b
;
+
----+-------------+------------+------+---------------+------+---------+------+------+-------------+
|
id
|
select_type
|
table
|
type
|
possible_keys
|
key
|
key_len
|
ref
|
rows
|
Extra
|
+
----+-------------+------------+------+---------------+------+---------+------+------+-------------+
|
1
|
PRIMARY
|
<
derived2
>
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
100
|
NULL
|
|
2
|
DERIVED
|
t2
|
ALL
|
NULL
|
NULL
|
NULL
|
NULL
|
100
|
Using
where
|
+
----+-------------+------------+------+---------------+------+---------+------+------+-------------+
2
rows
in
set
(
0
.
00 sec
)
阅读(541) | 评论(0) | 转发(0) |
0
上一篇:没有了
下一篇:没有了
给主人留下些什么吧!~~
评论热议
请登录后评论。
登录
注册