Ale*_*ing 116
最大基数:所有值都是唯一的
最小基数:所有值都相同
有些列称为高基数列,因为它们具有适当的约束(如唯一),禁止您在每一行中放置相同的值.
基数是一种影响数据聚类,排序和搜索能力的属性.因此,它是DB中查询规划器的重要度量,它是一种启发式方法,可用于选择最佳方案.
Mar*_*ith 15
根据Kami链接的维基百科文章,它基本上与列的值的唯一性程度相关联.
为什么重要的是要考虑它会影响索引策略.由于索引的选择性不足以使用,因此只有两个可能的值索引低基数列的点数很少.
Zon*_*Zon 10
基数越高,行的区分越好.差异化有助于导航较少的分支以获取数据.
因此,更高的统治价值意味着:
小智 7
在数学术语中,基数是一组值中的值的计数.集合只能包含唯一值.一个例子是集合"A".
设置"A"为:A = {1,2,3} - 该集的基数为| 3 |.
如果设置"A"包含5个值A = {10,21,33,42,57},则基数为| 5 |.
在mysql的上下文中,这意味着表列的基数是该列的唯一值的计数.如果您正在查看主键列的基数(例如table.id),那么该列的基数将告诉您该表包含多少行,因为表中的每一行都有一个唯一的ID.您不必在该表上执行"COUNT(*)"以查明它有多少行,只需查看基数即可.
小智 6
从手册中:
基数
索引中唯一值数量的估计。这是通过运行 ANALYZE TABLE 或 myisamchk -a 来更新的。基数是根据存储为整数的统计信息来计算的,因此即使对于小表,该值也不一定准确。基数越高,MySQL 在进行连接时使用索引的机会就越大。
Percona 的分析:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
70793 次 |
| 最近记录: |