mysql> explain a;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | UNI | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0.02 sec)
![]()
mysql> explain t;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | 0 | |
| MC | varchar(60) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
![]()
mysql> select * from t;
+-------+------+
| id | MC |
+-------+------+
| 1 | MC |
| 2 | NULL |
| 3 | NULL |
| 4 | NULL |
| 5 | NULL |
| 6 | NULL |
| 7 | NULL |
| 8 | NULL |
| 9 | NULL |
| 10000 | MC |
+-------+------+
10 rows in set (0.00 sec)
![]()
mysql> select * from a;
+------+
| id |
+------+
| NULL |
| 1 |
| 2 |
+------+
3 rows in set (0.00 sec)
![]()
mysql> explain select * from A where id in (select id from T)\G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: A
type: index
possible_keys: NULL
key: idx_a
key_len: 5
ref: NULL
rows: 3
Extra: Using where; Using index
*************************** 2. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: T
type: unique_subquery
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: func
rows: 1
Extra: Using index
2 rows in set (0.02 sec)
mysql> explain select * from test where id in (select id from a)\G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: test
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 1534755
Extra: Using where
*************************** 2. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: a
type: index_subquery
possible_keys: idx_a
key: idx_a
key_len: 5
ref: func
rows: 1
Extra: Using index
2 rows in set (0.00 sec)
mysql> explain select * from t where id=1 or id=10000 or id=3\G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t
type: range
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: NULL
rows: 3
Extra: Using where
1 row in set (0.00 sec)
![]()
mysql> explain select * from t where id<=3\G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t
type: range
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: NULL
rows: 4
Extra: Using where
1 row in set (0.00 sec)
![]()
ERROR:
No query specified
mysql> explain select * from t\G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t
type: index
possible_keys: NULL
key: idx_t_mc
key_len: 63
ref: NULL
rows: 10
Extra: Using index
1 row in set (0.00 sec)
![]()
ERROR:
No query specified
mysql> explain select * from test\G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: test
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 1534755
Extra:
1 row in set (0.06 sec)
![]()
ERROR:
No query specified
mysql> show index from t;
+-------+------------+----------+--------------+-------------+-----------+------
-------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardi
nality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+----------+--------------+-------------+-----------+------
-------+----------+--------+------+------------+---------+
| t | 0 | PRIMARY | 1 | id | A |
2 | NULL | NULL | | BTREE | |
| t | 1 | idx_t_mc | 1 | MC | A |
2 | NULL | NULL | YES | BTREE | |
+-------+------------+----------+--------------+-------------+-----------+------
-------+----------+--------+------+------------+---------+
2 rows in set (0.08 sec)
![]()
mysql> explain select * from t where id=1 or mc='1'\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t
type: index
possible_keys: PRIMARY,idx_t_mc
key: idx_t_mc
key_len: 63
ref: NULL
rows: 10
Extra: Using where; Using index
1 row in set (0.00 sec)
![]()
mysql> explain select * from t ignore index(idx_t_mc) where id=1 or mc='1'\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t
type: ALL
possible_keys: PRIMARY
key: NULL
key_len: NULL
ref: NULL
rows: 10
Extra: Using where
1 row in set (0.00 sec)
| 第1页: MYSQL服务器系统变量 | 第2页: MYSQL服务器状态变量 |
| 第3页: MYSQL服务器关键参数优化 | 第4页: 一个函数调试工具 |
| 第5页: MYSQL数据库的SQL执行计划解释器 | 第6页: 优化WHERE子句 |
| 第7页: MYSQL高速缓存管理 |