background image
5 分钟了解 MySQL5.7union all 用法的黑科技
union all 在 MySQL5.6 下的表现
Part1:MySQL5.6.25
1
2
3
4
5
6
7
8
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
[root@HE1 ~]
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection
id
is 2
Server version: 5.6.25-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights res
erved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type
'help;'
or
'\h'
for
help. Type
'\c'
to
clear
the current input st
atement.
mysql>
select
version();
+------------+
| version()
|
+------------+
| 5.6.25-log |
+------------+
1 row
in
set
(0.26 sec)
mysql> explain (
select id
from helei order by
id
) union all (
select id
from t where
id
=0 order by
id
);
+----+--------------+------------+-------+---------------+--------+---
------+------+------+-----------------+
|
id
| select_type
| table
|
type
| possible_keys | key
| ke
y_len | ref
| rows | Extra
|
+----+--------------+------------+-------+---------------+--------+---
------+------+------+-----------------+
|
1 | PRIMARY
| helei
| index | NULL
| idx_c1 | 4
| NULL | 5219 | Using index
|
|
2 | UNION
| t
| ALL
| NULL
| NULL
| NU
LL
| NULL |
1 | Using where
|
| NULL | UNION RESULT | <union1,2> | ALL
| NULL
| NULL
|
NULL
| NULL | NULL | Using temporary |
+----+--------------+------------+-------+---------------+--------+---
------+------+------+-----------------+
3 rows
in
set
(0.00 sec)