舉例解釋一下explain各欄位的含義
CREATE
TABLE table_user(
id
INT AUTO_INCREMENT,
user
VARCHAR(
30),
pwd
VARCHAR(
30),
description
VARCHAR(
90),
PRIMARY
KEY (
id));
CREATE
TABLE table_role(
id
INT AUTO_INCREMENT,
name
VARCHAR(
30),
description
VARCHAR(
90),
PRIMARY
KEY (
id));
CREATE
TABLE table_relation(
id
INT AUTO_INCREMENT,
user_id
INT,
role_id
INT,
FOREIGN
KEY (user_id)
REFERENCES table_user (
id),
FOREIGN
KEY (role_id)
REFERENCES table_role (
id),
PRIMARY
KEY (
id));
CREATE
TABLE table_partitions(
id
INT AUTO_INCREMENT,
name
VARCHAR(
30),
age
INT,
address
VARCHAR(
30),
PRIMARY
KEY (
id))
PARTITION
BY
HASH(
id)
PARTITIONS
2;
insert
into table_user(
user,pwd,description)
value(
'tony',
'abc123',
'admin');
insert
into table_user(
user,pwd,description)
value(
'tom',
'123456',
'general user');
insert
into table_user(
user,pwd,description)
value(
'jerry',
'123456',
'general user');
insert
into table_role(
name,description)
value(
'admin',
'admin role');
insert
into table_role(
name,description)
value(
'general',
'general role');
insert
into table_relation(user_id,role_id)
value(
1,
1);
insert
into table_relation(user_id,role_id)
value(
2,
2);
insert
into table_relation(user_id,role_id)
value(
3,
2);
insert
into table_partitions(
name,age,address)
value(
'wang',
21,
'shenzhen');
insert
into table_partitions(
name,age,address)
value(
'zhang',
23,
'shanghai');
insert
into table_partitions(
name,age,address)
value(
'li',
26,
'beijing');
CREATE INDEX index_age ON table_partitions(age);CREATE INDEX index_name_age ON table_partitions(name,age);
explain select * from table_role,table_user; #因為排版問題,去掉了一些資訊+----+-------------+------------+------------+------+---------------+------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+------------+------------+------+---------------+------+| 1 | SIMPLE | table_role | NULL | ALL | NULL | NULL || 1 | SIMPLE | table_user | NULL | ALL | NULL | NULL |+----+-------------+------------+------------+------+---------------+------+
explain select * from table_relation where role_id=(select id from table_role where name='admin');+----+-------------+----------------+------------+------+---------------+---------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+----------------+------------+------+---------------+---------+| 1 | PRIMARY | table_relation | NULL | ref | role_id | role_id || 2 | SUBQUERY | table_role | NULL | ALL | NULL | NULL |+----+-------------+----------------+------------+------+---------------+---------+
explain select * from (select version())temp;+----+-------------+------------+------------+--------+---------------+------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+------------+------------+--------+---------------+------+| 1 | PRIMARY | <derived2> | NULL | system | NULL | NULL || 2 | DERIVED | NULL | NULL | NULL | NULL | NULL |+----+-------------+------------+------------+--------+---------------+------+
explain select description from table_user union select description from table_role;+------+--------------+------------+------------+------+---------------+------+| id | select_type | table | partitions | type | possible_keys | key |+------+--------------+------------+------------+------+---------------+------+| 1 | PRIMARY | table_user | NULL | ALL | NULL | NULL || 2 | UNION | table_role | NULL | ALL | NULL | NULL || NULL | UNION RESULT | <union1,2> | NULL | ALL | NULL | NULL |+------+--------------+------------+------------+------+---------------+------+
explain select * from table_partitions where id=1;+----+-------------+------------------+------------+-------+---------------+---------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+------------------+------------+-------+---------------+---------+| 1 | SIMPLE | table_partitions | p1 | const | PRIMARY | PRIMARY |+----+-------------+------------------+------------+-------+---------------+---------+
explain select version();+----+-------------+-------+------------+------+---------------+------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+-------+------------+------+---------------+------+| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL |+----+-------------+-------+------------+------+---------------+------+
explain select * from table_partitions where id=1;+----+-------------+------------------+------------+-------+---------------+---------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+------------------+------------+-------+---------------+---------+| 1 | SIMPLE | table_partitions | p1 | const | PRIMARY | PRIMARY |+----+-------------+------------------+------------+-------+---------------+---------+
explain select * from table_relation join table_user where table_user.id=table_relation.user_id;+----+-------------+----------------+------------+--------+---------------+---------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+----------------+------------+--------+---------------+---------+| 1 | SIMPLE | table_relation | NULL | ALL | user_id | NULL || 1 | SIMPLE | table_user | NULL | eq_ref | PRIMARY | PRIMARY |+----+-------------+----------------+------------+--------+---------------+---------+
explain select * from table_partitions where name='zhang';+----+-------------+------------------+------------+------+----------------+----------------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+------------------+------------+------+----------------+----------------+| 1 | SIMPLE | table_partitions | p,p1 | ref | index_name_age | index_name_age |+----+-------------+------------------+------------+------+----------------+----------------+
explain select * from table_partitions where name like 'zhang';+----+-------------+------------------+------------+-------+----------------+----------------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+------------------+------------+-------+----------------+----------------+| 1 | SIMPLE | table_partitions | p,p1 | range | index_name_age | index_name_age |+----+-------------+------------------+------------+-------+----------------+----------------+
explain select name from table_partitions;+----+-------------+------------------+------------+-------+---------------+----------------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+------------------+------------+-------+---------------+----------------+| 1 | SIMPLE | table_partitions | p,p1 | index | NULL | index_name_age |+----+-------------+------------------+------------+-------+---------------+----------------+
explain select * from table_partitions;+----+-------------+------------------+------------+------+---------------+------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+------------------+------------+------+---------------+------+| 1 | SIMPLE | table_partitions | p,p1 | ALL | NULL | NULL |+----+-------------+------------------+------------+------+---------------+------+
explain select * from table_partitions where name='zhang' and age=20;+----+-------------+------------------+------------+------+--------------------------+-----------+| id | select_type | table | partitions | type | possible_keys | key |+----+-------------+------------------+------------+------+--------------------------+-----------+| 1 | SIMPLE | table_partitions | p,p1 | ref | index_age,index_name_age | index_age |+----+-------------+------------------+------------+------+--------------------------+-----------+
explain select name from table_partitions;+----+-------+----------------+---------+------+------+----------+-------------+| id | type | key | key_len | ref | rows | filtered | Extra |+----+-------+----------------+---------+------+------+----------+-------------+| 1 | index | index_name_age | 128 | NULL | 1 | 100.00 | Using index |+----+-------+----------------+---------+------+------+----------+-------------+
explain select age from table_partitions;+----+-------+-----------+---------+------+------+----------+-------------+| id | type | key | key_len | ref | rows | filtered | Extra |+----+-------+-----------+---------+------+------+----------+-------------+| 1 | index | index_age | 5 | NULL | 1 | 100.00 | Using index |+----+-------+-----------+---------+------+------+----------+-------------+
explain select name from table_partitions where name='zhang';+----+------+----------------+---------+-------+------+----------+-------------+| id | type | key | key_len | ref | rows | filtered | Extra |+----+------+----------------+---------+-------+------+----------+-------------+| 1 | ref | index_name_age | 123 | const | 1 | 100.00 | Using index |+----+------+----------------+---------+-------+------+----------+-------------+
explain select table_relation.id from table_relation,table_role where role_id=table_role.id;+----+-------+---------+---------+--------------------+------+----------+-------------+| id | type | key | key_len | ref | rows | filtered | Extra |+----+-------+---------+---------+--------------------+------+----------+-------------+| 1 | index | PRIMARY | 4 | NULL | 2 | 100.00 | Using index || 1 | ref | role_id | 5 | mydb.table_role.id | 1 | 100.00 | Using index |+----+-------+---------+---------+--------------------+------+----------+-------------+
explain select age from table_partitions where age>18;+----+-------+-----------+---------+------+------+----------+--------------------------+| id | type | key | key_len | ref | rows | filtered | Extra |+----+-------+-----------+---------+------+------+----------+--------------------------+| 1 | index | index_age | 5 | NULL | 3 | 100.00 | Using where; Using index |+----+-------+-----------+---------+------+------+----------+--------------------------+
explain select * from table_user where description='admin';+----+------+---------------+------+---------+------+------+----------+-------------+| id | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+------+---------------+------+---------+------+------+----------+-------------+| 1 | ALL | NULL | NULL | NULL | NULL | 3 | 33.33 | Using where |+----+------+---------------+------+---------+------+------+----------+-------------+
-
Using index查詢到的列被索引覆蓋,實際上就是覆蓋索引的使用。
-
Using where查詢未用到可用的索引,透過where條件過濾資料。
-
Using where,Using index透過where條件過濾資料,並且查詢用到了覆蓋索引。
-
Using index condition查詢使用到了索引,但是需要回表查詢。
-
Using temporary查詢後結果需要使用臨時表來儲存,一般在排序或者分組查詢時用到。
-
Using filesort無法利用索引完成的排序操作,也就是ORDER BY的欄位沒有索引。
-
Using join buffer在我們聯表查詢的時候,如果表的連線條件沒有用到索引,需要有一個連線緩衝區來儲存中間結果。
-
Impossible where在我們用不太正確的where語句,導致沒有符合條件的行。
-
No tables used我們的查詢語句中沒有FROM子句,或者有FROM DUAL子句。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70011764/viewspace-2855964/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 卡卡西:一文詳解explain各欄位含義AI
- Explain各列的含義AI
- topas 中 PgSp 欄位的含義
- explain中filesort含義AI
- explain結果含義AI
- linux top命令欄位含義Linux
- EXPLAIN結果含義(轉)AI
- v$session中command欄位的含義解析Session
- mysql explain用法和結果的含義MySqlAI
- 誰能解釋一下 Rest style service的含義?REST
- [高頻面試]解釋執行緒池的各個引數含義面試執行緒
- 總結一下公共欄位(aop加自定義註解加反射)反射
- samtools各種flag的含義
- ABAP 資料庫表 Size Category 欄位的準確含義資料庫Go
- iOS開發Xcode中的Info.plist欄位含義iOSXCode
- HTTP header 欄位解釋HTTPHeader
- 理解V$LOCK.ID1和ID2欄位的含義
- HTTP 請求響應頭部欄位裡 ETAG 的用法舉例HTTP
- 使用kubectl explain來了解可能的API物件欄位AIAPI物件
- yslow各個指標含義指標
- oracleasm各個選項含義OracleASM
- odoo欄位屬性列舉Odoo
- Linux各種變數的含義Linux變數
- MySQL 5.7中sql_mode的含義解釋MySql
- SAP ABAP 中,if_http_extension 介面的flow_rc 欄位含義HTTP
- oracle會話阻塞查詢指令碼及對應欄位含義Oracle會話指令碼
- JS標籤的各種事件的舉例JS事件
- HTTP 請求頭部欄位中 connection - keep-alive 的含義HTTPKeep-Alive
- 設計模式之依賴倒置原則含義及現實舉例設計模式
- http請求頭個欄位解釋HTTP
- Oracle Statspack各項指標含義Oracle指標
- /proc/loadavg 各項資料的含義
- DEDE檢測重複自定義欄位禁止釋出
- Oracle Statspack報告中各項指標含義詳解!Oracle指標
- Oracle Statspack報告中各項指標含義詳解Oracle指標
- all_constraints 表欄位Constraint_type值含義AI
- 深度學習 | sklearn的train_test_split()各函式引數含義解釋(超級全)深度學習AI函式
- php二進位制安全的含義PHP