Skip to content

schema_unused_indexes

xiaoboluo768 edited this page Jun 9, 2020 · 2 revisions
  • 查看不活跃的索引(没有任何事件发生的索引,这表示该索引从未使用过),默认情况下按照schema名称和表名进行排序。数据来源:table_io_waits_summary_by_index_usage

    • 该视图在server启动之后运行足够长的时间之后,所查询出的数据才比较适用,否则该视图查询的数据可能并不十分可靠,因为统计的数据可能并不精确,有一部分业务查询逻辑可能还来不及查询
  • schema_unused_indexes视图字段含义如下:

    • object_schema:schema名称
    • OBJECT_NAME:表名
    • INDEX_NAME:未使用的索引名称
  • 视图定义语句

CREATE OR REPLACE
  ALGORITHM = MERGE
  DEFINER = 'root'@'localhost'
  SQL SECURITY INVOKER
VIEW schema_unused_indexes (
  object_schema,  object_name,  index_name
) AS
SELECT object_schema,
      object_name,
      index_name
  FROM performance_schema.table_io_waits_summary_by_index_usage
WHERE index_name IS NOT NULL
  AND count_star = 0
  AND object_schema != 'mysql'
  AND index_name != 'PRIMARY'
ORDER BY object_schema, object_name;
  • 视图查询信息示例
admin@localhost : sys 12:40:28> select * from schema_unused_indexes limit 3;
+---------------+-------------+-------------------+
| object_schema | object_name | index_name        |
+---------------+-------------+-------------------+
| luoxiaobo    | public_num  | public_name_index |
| sbtest        | sbtest1    | k_1              |
| sbtest        | sbtest2    | k_2              |
+---------------+-------------+-------------------+
3 rows in set (0.00 sec)

上一篇: schema_tables_with_full_table_scans,x$schema_tables_with_full_table_scans视图 |

下一篇: session,x$session视图

Clone this wiki locally