Answers:
最大基数:所有值都是唯一的
最小基数:所有值都相同
有些列称为高基数列,因为它们具有适当的约束(例如唯一性),禁止您在每行中输入相同的值。
基数是影响聚类,排序和搜索数据能力的属性。因此,对于数据库中的查询计划者而言,这是一项重要的衡量标准,这是一种启发式方法,他们可以用来选择最佳计划。
从手册:
基数
索引中唯一值数量的估计。通过运行ANALYZE TABLE或myisamchk -a可以对此进行更新。基数是根据存储为整数的统计数据进行计数的,因此即使对于较小的表,该值也不一定准确。基数越高,MySQL在进行联接时使用索引的机会就越大。
CREATE TABLE `antest` (
`i` int(10) unsigned NOT NULL,
`c` char(80) default NULL,
KEY `i` (`i`),
KEY `c` (`c`,`i`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
mysql> select count(distinct c) from antest;
+-------------------+
| count(distinct c) |
+-------------------+
| 101 |
+-------------------+
1 row in set (0.36 sec)
mysql> select count(distinct i) from antest;
+-------------------+
| count(distinct i) |
+-------------------+
| 101 |
+-------------------+
1 row in set (0.20 sec)
mysql> select count(distinct i,c) from antest;
+---------------------+
| count(distinct i,c) |
+---------------------+
| 10201 |
+---------------------+
1 row in set (0.43 sec)
mysql> show index from antest;
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| antest | 1 | i | 1 | i | A | NULL | NULL | NULL | | BTREE | |
| antest | 1 | c | 1 | c | A | NULL | NULL | NULL | YES | BTREE | |
| antest | 1 | c | 2 | i | A | NULL | NULL | NULL | | BTREE | |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
3 rows in set (0.00 sec)
mysql> analyze table sys_users;
+--------------------------------+---------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+--------------------------------+---------+----------+----------+
| antest | analyze | status | OK |
+--------------------------------+---------+----------+----------+
1 row in set (0.01 sec)
mysql> show index from antest;
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| antest | 1 | i | 1 | i | A | 101 | NULL | NULL | | BTREE | |
| antest | 1 | c | 1 | c | A | 101 | NULL | NULL | YES | BTREE | |
| antest | 1 | c | 2 | i | A | 10240 | NULL | NULL | | BTREE | |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
3 rows in set (0.01 sec)