我首先在我的表中创建了 2 个单独的索引:uid 和 time。然后我决定创建一个复合索引(uid,时间)。但是为什么复合索引(第 3 行)中 uid 的基数小于单个索引(第 1 行)中 uid 的基数?
mysql> show index from full_data;
+-----------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-----------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| full_data | 1 | uid | 1 | uid | A | 26394792 | NULL | NULL | YES | BTREE | | |
| full_data | 1 | time | 1 | time | A | 6934463 | NULL | NULL | YES | BTREE | | |
| full_data | 1 | composite | 1 | uid | A | 23166632 | NULL | NULL | YES | BTREE | | |
| full_data | 1 | composite | 2 | time | A | 86380688 | NULL | NULL | YES | BTREE | | |
+-----------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
4 rows in set (0.05 sec)