zoukankan      html  css  js  c++  java
  • show index 之Cardinality (mysql)

    show index  之Cardinality

    官方文档的解释:

    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.
     

    总结一下:
    1. cardinality简单的说就是,你索引列的唯一值的个数,既基数。

        如果是复合索引就是唯一组合的个数。 (需要注意的是这个值并不是特别准确的,每执行下命令,这个值可能都会不同)

    2. 这个数值将会作为mysql优化器对语句执行计划进行判定时依据。

        如果唯一性太小,那么优化器会认为,这个索引对语句没有太大帮助,而不使用索引。

       如果cardinality值越大,就意味着,使用索引能排除越多的数据,执行也更为高效, 这个值越大在做表连接的时候,就越有机会选择这个索引。。

    3. MyISAM存储引擎与InnoDB存储引擎在NULL上对于Cardinality的计算方式不同

    例如:
    a,b,c
    1,1,1
    1,1,2
    1,2,1
    1,2,2
    2,1,1
    2,1,2
    2,2,1
    2,2,2
    假如你对a列作索引,那么它的cardinality就是2,因为此列只有1和2两个值。
    假如你对a,b列作复合索引,那么它的cardinality就是4,因为这两列有(1,2),(1,1),(2,1),(2,2)这几种组合。
    假如你对a,b,c作复合索引,那么它的cardinality就是8.........
  • 相关阅读:
    Spring Security -- 添加图形验证码(转载)
    Spring Security -- 自定义用户认证(转载)
    pandas agg 后降低df表层
    判断是否有人跟踪车辆的方案
    格隆汇笔记-黄勇演讲
    Mac mysql 忘记root密码的解决方法
    sql 同步2个表中的一个字段数据
    Linux下配置用msmtp和mutt发邮件
    spark StructType的应用,用在处理mongoDB keyvalue
    Idea2018旗舰版破解方法
  • 原文地址:https://www.cnblogs.com/zjrodger/p/4459249.html
Copyright © 2011-2022 走看看