mysql> CREATE TABLE `test_test` (
-> `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
-> `uid` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'uid',
-> `update_time` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'update_time 单位:s',
-> PRIMARY KEY (`id`),
-> KEY `idx_uid_update_time` (`uid`,`update_time`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.02 sec)
mysql> insert into test_test(uid,update_time) values (1,111);
Query OK, 1 row affected (0.01 sec)
mysql> insert into test_test(uid,update_time) values (2,111);
Query OK, 1 row affected (0.00 sec)
mysql> insert into test_test(uid,update_time) values (1,222);
Query OK, 1 row affected (0.00 sec)
mysql> insert into test_test(uid,update_time) values (1,333);
Query OK, 1 row affected (0.01 sec)
mysql> select * from test_test;
+----+-----+-------------+
| id | uid | update_time |
+----+-----+-------------+
| 1 | 1 | 111 |
| 3 | 1 | 222 |
| 4 | 1 | 333 |
| 2 | 2 | 111 |
+----+-----+-------------+
4 rows in set (0.00 sec)
mysql> desc select * from test_test;
+----+-------------+-----------+------------+-------+---------------+---------------------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-----------+------------+-------+---------------+---------------------+---------+------+------+----------+-------------+
| 1 | SIMPLE | test_test | NULL | index | NULL | idx_uid_update_time | 16 | NULL | 4 | 100.00 | Using index |
+----+-------------+-----------+------------+-------+---------------+---------------------+---------+------+------+----------+-------------+
Q: 用的是innodb引擎,默认为啥不是按照 主键 去排查的呢。