zoukankan      html  css  js  c++  java
  • MySQL index使用率查询

    SELECT
      t.table_schema AS db,
      t.table_name   AS tab_name,
      s.index_name   AS index_name,
      s.column_name  AS field_name,
      s.seq_in_index  AS  seq_in_index,
      s2.max_columns AS max_col,
      s.cardinality  AS cardinality,
      t.table_rows   AS table_rows, 
      ROUND(((s.CARDINALITY / IFNULL(t.TABLE_ROWS, 0.01)) * 100), 2) AS sel
    FROM information_schema.statistics s
      INNER JOIN information_schema.tables t
        ON s.table_schema = t.table_schema
          AND s.table_name = t.table_name
      INNER JOIN (SELECT
                    table_schema,
                    table_name,
                    index_name,
                    MAX(seq_in_index) AS max_columns
                  FROM information_schema.statistics
                  WHERE table_schema != 'mysql'
                  GROUP BY table_schema, table_name, index_name) AS s2
        ON s.table_schema = s2.table_schema
          AND s.table_name = s2.table_name
          AND s.index_name = s2.index_name
    WHERE t.table_schema != 'mysql'
        AND t.table_rows > 100
        AND s.CARDINALITY IS NOT NULL
        AND (s.CARDINALITY / IFNULL(t.TABLE_ROWS, 0.01)) < 1.00
    ORDER BY sel, s.table_schema, s.table_name
    LIMIT 10

    待验证

  • 相关阅读:
    HTML5 中的Nav元素详解
    Gevent中信号量的使用
    MemCache缓存multiget hole详解
    MemCache中的内存管理详解
    Php中的强制转换详解
    Python中类的特殊方法详解
    MemCache的LRU删除机制详解
    AngularJS事件绑定的使用详解
    Php数据类型之整型详解
    HTML基础知识
  • 原文地址:https://www.cnblogs.com/xibuhaohao/p/11038576.html
Copyright © 2011-2022 走看看