官方mysql中檢視索引是否被使用到
官方mysql中檢視索引是否被使用到:
在percona版本或marida中可以通過 information_schea.index_statistics檢視得到,
在官方版本中如何檢視呢?
select object_type,object_schema,object_name,index_name,count_star,count_read,COUNT_FETCH from performance_schema.table_io_waits_summary_by_index_usage;
應該可以通過上面的sql得到。 如果read,fetch的次數都為0的話,應該是沒有被使用過的。
通過下面的例子,可以證實:
啟動mysql:
mysql> show create table a.t3;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t3 | CREATE TABLE `t3` (
`id` int(11) DEFAULT NULL,
`name` varchar(10) NOT NULL DEFAULT 'bb',
KEY `idx_t3` (`id`),
KEY `idx_t3_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
mysql> select object_type,object_schema,object_name,index_name,count_star,count_read,COUNT_FETCH from performance_schema.table_io_waits_summary_by_index_usage where object_name='t3';
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| object_type | object_schema | object_name | index_name | count_star | count_read | COUNT_FETCH |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| TABLE | a | t3 | idx_t3 | 0 | 0 | 0 |
| TABLE | a | t3 | idx_t3_name | 0 | 0 | 0 |
| TABLE | a | t3 | NULL | 0 | 0 | 0 |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
3 rows in set (0.01 sec)
mysql> explain select id from t3 where id=1;
ERROR 1046 (3D000): No database selected
mysql> explain select id from a.t3 where id=1;
+----+-------------+-------+------+---------------+--------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+--------+---------+-------+------+-------------+
| 1 | SIMPLE | t3 | ref | idx_t3 | idx_t3 | 5 | const | 1 | Using index |
+----+-------------+-------+------+---------------+--------+---------+-------+------+-------------+
1 row in set (0.00 sec)
mysql> select object_type,object_schema,object_name,index_name,count_star,count_read,COUNT_FETCH from performance_schema.table_io_waits_summary_by_index_usage where object_name='t3';
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| object_type | object_schema | object_name | index_name | count_star | count_read | COUNT_FETCH |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| TABLE | a | t3 | idx_t3 | 0 | 0 | 0 |
| TABLE | a | t3 | idx_t3_name | 0 | 0 | 0 |
| TABLE | a | t3 | NULL | 0 | 0 | 0 |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
3 rows in set (0.01 sec)
mysql> use a;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select id from t3 where id=1;
Empty set (0.00 sec)
mysql> select object_type,object_schema,object_name,index_name,count_star,count_read,COUNT_FETCH from performance_schema.table_io_waits_summary_by_index_usage where object_name='t3';
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| object_type | object_schema | object_name | index_name | count_star | count_read | COUNT_FETCH |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| TABLE | a | t3 | idx_t3 | 1 | 1 | 1 |
| TABLE | a | t3 | idx_t3_name | 0 | 0 | 0 |
| TABLE | a | t3 | NULL | 0 | 0 | 0 |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
3 rows in set (0.00 sec)
mysql> select id from t3 where id=10; +------+
| id |
+------+
| 10 |
| 10 |
+------+
2 rows in set (0.00 sec)
mysql> select object_type,object_schema,object_name,index_name,count_star,count_read,COUNT_FETCH from performance_schema.table_io_waits_summary_by_index_usage where object_name='t3';
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| object_type | object_schema | object_name | index_name | count_star | count_read | COUNT_FETCH |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| TABLE | a | t3 | idx_t3 | 4 | 4 | 4 |
| TABLE | a | t3 | idx_t3_name | 0 | 0 | 0 |
| TABLE | a | t3 | NULL | 0 | 0 | 0 |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
3 rows in set (0.01 sec)
mysql> select name from t3 where name='a';
Empty set (0.00 sec)
mysql> select object_type,object_schema,object_name,index_name,count_star,count_read,COUNT_FETCH from performance_schema.table_io_waits_summary_by_index_usage where object_name='t3';
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| object_type | object_schema | object_name | index_name | count_star | count_read | COUNT_FETCH |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| TABLE | a | t3 | idx_t3 | 4 | 4 | 4 |
| TABLE | a | t3 | idx_t3_name | 1 | 1 | 1 |
| TABLE | a | t3 | NULL | 0 | 0 | 0 |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
3 rows in set (0.01 sec)
mysql> select name from t3 where name='name1';
+-------+
| name |
+-------+
| name1 |
+-------+
1 row in set (0.01 sec)
mysql> select object_type,object_schema,object_name,index_name,count_star,count_read,COUNT_FETCH from performance_schema.table_io_waits_summary_by_index_usage where object_name='t3';
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| object_type | object_schema | object_name | index_name | count_star | count_read | COUNT_FETCH |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
| TABLE | a | t3 | idx_t3 | 4 | 4 | 4 |
| TABLE | a | t3 | idx_t3_name | 3 | 3 | 3 |
| TABLE | a | t3 | NULL | 0 | 0 | 0 |
+-------------+---------------+-------------+-------------+------------+------------+-------------+
3 rows in set (0.01 sec)
索引被使用之後, 對應的值會增加。
轉載請註明源出處
QQ 273002188 歡迎一起學習
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25099483/viewspace-1680455/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Linux中如何檢視8080埠是否被佔用?Linux
- mysql建立索引和檢視MySql索引
- LINUX中如何檢視某個埠是否被佔用Linux
- 怎麼檢視網站是否被谷歌收錄,檢視網站是否被谷歌收錄的快速檢測方法網站谷歌
- LINUX中埠是否被佔用應該如何檢視呢?Linux
- linux下檢視埠是否被佔用以及檢視所有埠Linux
- 怎麼檢視網站是否被谷歌收錄,檢視網站是否被谷歌收錄的詳細步驟網站谷歌
- MySql ORDER BY索引是否失效MySql索引
- 檢視Linux埠是否被開放@[環境部署]Linux
- Oracle檢視歸檔是否被備庫應用Oracle
- Linux中如何檢測系統是否被入侵Linux
- 怎麼檢視網站是否被谷歌收錄,你會檢視網站被谷歌收錄的方法嗎網站谷歌
- mongodb 如何檢視索引MongoDB索引
- JavaScript檢測window.open()彈出視窗是否被攔截JavaScript
- Mysql利用explain確認是否使用索引MySqlAI索引
- Java檢測埠是否被佔用Java
- Linux中檢視指令碼程式是否存在的命令!Linux指令碼
- MYSQL 檢視MySql
- linux檢測系統是否被入侵(上)Linux
- 如何檢視是否安裝postgresqlSQL
- 檢視tensorflow,pytorch是否可用GPUPyTorchGPU
- [20180503]檢視提示使用索引.txt索引
- 【Mongo】MongoDB索引管理-索引的建立、檢視、刪除MongoDB索引
- Oracle 如何高效的檢視官方文件Oracle
- win10系統如何檢視自己電腦有沒有被監控_win10怎麼檢視自己電腦是否被監控Win10
- MySQL View 檢視MySqlView
- 怎麼檢測伺服器是否被入侵伺服器
- Android 應用檢測裝置是否被rootAndroid
- 2020重新出發,MySql基礎,MySql檢視&索引&儲存過程&觸發器MySql索引儲存過程觸發器
- MySQL null值欄位是否使用索引的總結MySqlNull索引
- 如何檢視 Apache 模組是否正常Apache
- linux檢視埠是否被佔用的命令是什麼 linux被哪個程式佔用命令介紹Linux
- mysql的新建索引會導致insert被lockedMySql索引
- MySQL檢視介紹MySql
- 管理mysql的檢視MySql
- MySQL 檢視簡介MySql
- 10_MySQL檢視MySql
- 如何判斷sql中的索引是否生效SQL索引
- win10怎麼檢視expressCache功能是否正常_win10檢視expressCache功能是否正常的方法Win10Express