舉例解釋一下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
- linux top命令欄位含義Linux
- EXPLAIN結果含義(轉)AI
- [高頻面試]解釋執行緒池的各個引數含義面試執行緒
- HTTP header 欄位解釋HTTPHeader
- samtools各種flag的含義
- 總結一下公共欄位(aop加自定義註解加反射)反射
- ABAP 資料庫表 Size Category 欄位的準確含義資料庫Go
- distinct 全部欄位和單列的含義和注意事項,
- 使用kubectl explain來了解可能的API物件欄位AIAPI物件
- HTTP 請求響應頭部欄位裡 ETAG 的用法舉例HTTP
- HTTP 請求頭部欄位中 connection - keep-alive 的含義HTTPKeep-Alive
- Linux各種變數的含義Linux變數
- 深度學習 | sklearn的train_test_split()各函式引數含義解釋(超級全)深度學習AI函式
- odoo欄位屬性列舉Odoo
- SAP ABAP 中,if_http_extension 介面的flow_rc 欄位含義HTTP
- /etc/shadow檔案相關欄位的解釋
- http請求頭個欄位解釋HTTP
- Chrome Network 下邊欄中 Finish 的含義Chrome
- JTAG各類介面針腳定義及含義
- MySQL欄位新增註釋,但不改變欄位的型別MySql型別
- maven遠端倉庫配置及含義解釋Maven
- Request 增加自定義欄位的方式
- 類圖各個箭頭和符號的含義符號
- Nginx訪問日誌詳解——各個部分含義——非常簡單Nginx
- PhpCms自定義欄位的使用說明PHP
- 有關 HTTP 快取的首部欄位說一下HTTP快取
- CPU使用率的幾個重要指標含義列舉指標
- 列舉直播搭建過程中SDK的含義及優勢
- 說一下泛型原理,並舉例說明泛型
- 自定義元件-純資料欄位元件
- 請教一下 多欄位值如何排序?排序
- git merge合併程式碼時各引數含義Git
- 解累積流圖的真正含義
- DedeCMS的checkbox多選欄位自定義取值的方法
- MySQL explain執行計劃詳細解釋MySqlAI
- laravel model自定義軟刪除欄位Laravel
- 【掃盲篇】衛生資訊資料集欄位解釋