Percona 5.5定位未使用的索引
開啟userstat引數,然後讓MySQL執行一段時間。
之後可以在INFORMATION_SCHEMA.INDEX_STATISTICS表中查詢到索引的使用頻率。
之後可以在INFORMATION_SCHEMA.INDEX_STATISTICS表中查詢到索引的使用頻率。
-
mysql> show global variables like '%users%';
-
+---------------+-------+
-
| Variable_name | Value |
-
+---------------+-------+
-
| userstat | OFF |
-
+---------------+-------+
-
1 row in set (0.00 sec)
-
-
mysql> select * from information_schema.index_statistics;
-
Empty set (0.00 sec)
-
-
mysql> set global userstat=1;
-
Query OK, 0 rows affected (0.00 sec)
-
-
mysql> show global variables like '%users%';
-
+---------------+-------+
-
| Variable_name | Value |
-
+---------------+-------+
-
| userstat | ON |
-
+---------------+-------+
-
1 row in set (0.00 sec)
-
-
mysql> select * from information_schema.index_statistics;
-
Empty set (0.00 sec)
-
-
mysql> explain select * from emp where hiredate > '1982-01-01' and deptno = 20;
-
+----+-------------+-------+-------+---------------------------+------------------+---------+------+------+-------------+
-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
-
+----+-------------+-------+-------+---------------------------+------------------+---------+------+------+-------------+
-
| 1 | SIMPLE | emp | range | idx_date_sal_job,idx_date | idx_date_sal_job | 4 | NULL | 3 | Using where |
-
+----+-------------+-------+-------+---------------------------+------------------+---------+------+------+-------------+
-
1 row in set (0.00 sec)
-
-
mysql> select * from information_schema.index_statistics;
-
Empty set (0.00 sec)
-
-
mysql> select * from emp where hiredate > '1982-01-01' and deptno = 20;
-
+-------+-------+---------+------+---------------------+------+------+--------+
-
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
-
+-------+-------+---------+------+---------------------+------+------+--------+
-
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 00:00:00 | 3000 | NULL | 20 |
-
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 00:00:00 | 1100 | NULL | 20 |
-
+-------+-------+---------+------+---------------------+------+------+--------+
-
2 rows in set (0.00 sec)
-
-
mysql> select * from information_schema.index_statistics;
-
+--------------+------------+------------------+-----------+
-
| TABLE_SCHEMA | TABLE_NAME | INDEX_NAME | ROWS_READ |
-
+--------------+------------+------------------+-----------+
-
| test | emp | idx_date_sal_job | 3 |
-
+--------------+------------+------------------+-----------+
-
1 row in set (0.04 sec)
-
-
mysql> select * from emp;
-
+-------+--------+-----------+------+---------------------+------+------+--------+
-
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
-
+-------+--------+-----------+------+---------------------+------+------+--------+
-
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800 | NULL | 20 |
-
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600 | 300 | 30 |
-
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250 | 500 | 30 |
-
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975 | NULL | 20 |
-
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250 | 1400 | 30 |
-
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850 | NULL | 30 |
-
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450 | NULL | 10 |
-
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 00:00:00 | 3000 | NULL | 20 |
-
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000 | NULL | 10 |
-
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500 | 0 | 30 |
-
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 00:00:00 | 1100 | NULL | 20 |
-
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950 | NULL | 30 |
-
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000 | NULL | 20 |
-
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300 | NULL | 10 |
-
+-------+--------+-----------+------+---------------------+------+------+--------+
-
14 rows in set (0.00 sec)
-
-
mysql> select * from information_schema.index_statistics;
-
+--------------+------------+------------------+-----------+
-
| TABLE_SCHEMA | TABLE_NAME | INDEX_NAME | ROWS_READ |
-
+--------------+------------+------------------+-----------+
-
| test | emp | PRIMARY | 14 |
-
| test | emp | idx_date_sal_job | 3 |
-
+--------------+------------+------------------+-----------+
-
2 rows in set (0.00 sec)
-
-
mysql> select * from emp where hiredate > '1982-01-01' and deptno = 20;
-
+-------+-------+---------+------+---------------------+------+------+--------+
-
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
-
+-------+-------+---------+------+---------------------+------+------+--------+
-
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 00:00:00 | 3000 | NULL | 20 |
-
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 00:00:00 | 1100 | NULL | 20 |
-
+-------+-------+---------+------+---------------------+------+------+--------+
-
2 rows in set (0.00 sec)
-
-
mysql> select * from emp;
-
+-------+--------+-----------+------+---------------------+------+------+--------+
-
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
-
+-------+--------+-----------+------+---------------------+------+------+--------+
-
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800 | NULL | 20 |
-
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600 | 300 | 30 |
-
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250 | 500 | 30 |
-
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975 | NULL | 20 |
-
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250 | 1400 | 30 |
-
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850 | NULL | 30 |
-
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450 | NULL | 10 |
-
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 00:00:00 | 3000 | NULL | 20 |
-
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000 | NULL | 10 |
-
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500 | 0 | 30 |
-
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 00:00:00 | 1100 | NULL | 20 |
-
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950 | NULL | 30 |
-
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000 | NULL | 20 |
-
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300 | NULL | 10 |
-
+-------+--------+-----------+------+---------------------+------+------+--------+
-
14 rows in set (0.00 sec)
-
-
mysql> select * from information_schema.index_statistics;
-
+--------------+------------+------------------+-----------+
-
| TABLE_SCHEMA | TABLE_NAME | INDEX_NAME | ROWS_READ |
-
+--------------+------------+------------------+-----------+
-
| test | emp | PRIMARY | 28 |
-
| test | emp | idx_date_sal_job | 6 |
-
+--------------+------------+------------------+-----------+
- 2 rows in set (0.00 sec)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2150859/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- percona server5.6跟5.5的差異統計Server
- MySQL 5.5 刪除索引的方法MySql索引
- 原因定位:Oracle為何不能使用索引(轉)Oracle索引
- 快速定位不合理的索引——MySQL索引調優索引MySql
- Percona MySQL 5.6 WHERE 條件中 OR 的索引測試MySql索引
- Percona MySQL 5.5 Linux通用二進位制包安裝(CentOS 6.9)MySqlLinuxCentOS
- MySQL 5.6快速定位不合理索引MySql索引
- 索引的使用索引
- 【索引】oracle查詢使用索引和不使用索引的比較索引Oracle
- 【索引】使用索引分析快速得到索引的基本資訊索引
- 模擬生產環境MySQL5.5升級Percona5.6演示步驟薦MySql
- 安裝並使用percona-toolkit
- percona-toolkit效能類工具的使用介紹
- percona-toolkit工具包的安裝和使用
- mysql 5.5 索引建設(表rebuild)過程中的系統崩潰的恢復MySql索引Rebuild
- 未使用到的
- Oracle索引HINT的使用Oracle索引
- 談談Babel v6的新特性及未來定位Babel
- Laravel 5.5 validator 使用 request fromLaravel
- 使用Elasticsearch的動態索引和索引優化Elasticsearch索引優化
- 使用聚集索引和非聚集索引的區別索引
- 使用percona-toolkit操作MySQL的實用命令小結MySql
- zabbix使用percona監控mysql資料庫MySql資料庫
- Percona 5.6 thread pool說明及使用thread
- 索引監控-查詢從未被使用過的索引索引
- Mysql索引的使用-組合索引+跳躍條件MySql索引
- 跳過索引某些列任然使用索引的特性索引
- 索引使用的基本原則索引
- MySQL全文索引的使用MySql索引
- 索引的八種使用模式索引模式
- 關於索引的使用模式索引模式
- Oracle索引的使用規則Oracle索引
- ORACLE 監控索引的使用Oracle索引
- [zt] SQLSERVER索引的使用技巧SQLServer索引
- MySQL的索引原理及使用MySql索引
- Mysql資料庫是如何通過索引定位資料MySql資料庫索引
- mongodb索引使用MongoDB索引
- Mysql索引使用MySql索引