zoukankan      html  css  js  c++  java
  • MySQL里执行SHOW INDEX结果中Cardinality的含义

    今天在写一个Perl脚本,想自动化查找出MySQL数据库中可能无效的索引,于是根据朝阳的书上提到的一些规则,我来设计了一些判断方法,其中发现某个我想要的值就是SHOW INDEX FROM table里的Cardinality,于是查了下它的含义以验证我的想法。

    MySQL中SHOW INDEX FROM table 会有以下结果列

    | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |

    我想知道的是Cardinality列的含义。
    查看官方文档的解释:
    An estimate of the number of unique values in the index. This is updated by running ANALYZE TABLE or myisamchk -a. Cardinality is counted based on statistics stored as integers, so the value is not necessarily exact even for small tables. The higher the cardinality, the greater the chance that MySQL uses the index when doing joins.

    所以这个Cardinality会有如下的含义:
    1. 列值代表的是此列中存储的唯一值的个数(如果此列为primary key 则值为记录的行数)
    2. 列值只是个估计值,并不准确。
    3. 列值不会自动更新,需要通过Analyze table来更新一张表或者mysqlcheck -Aa来进行更新整个数据库。
    4. 列值的大小影响Join时是否选用这个Index的判断。
    5. 创建Index时,MyISAM的表Cardinality的值为null,InnoDB的表Cardinality的值大概为行数。
    6. MyISAM与InnoDB对于Cardinality的计算方式不同。

    参考:

    http://www.penglixun.com/tech/database/mysql_show_index_cardinality.html

  • 相关阅读:
    存储过程
    pl/sql锁
    事务处理
    记录类型(学习笔记)
    ExecutorException: A query was run and no Result Maps were found for the Mapped Statement ''. It's likely that neither a Result Type nor a Result Map was specified.
    element中的el-form踩的坑
    关于location.href家族的区别和用法
    ajax的路径跳转
    使用thymeleaf模板引擎时的路径问题
    关于mybatis的传多个参数的问题
  • 原文地址:https://www.cnblogs.com/xiaotengyi/p/3556761.html
Copyright © 2011-2022 走看看