依照楼主的数据,我也造了400万数据:
mysql> select * from index_test limit 5;
id1
id2
11111
11111
22222
22222
11111
11111
22222
22222
11111
11111
id1创建索引
执行确实是id2谓词条件比较快:
mysql> select * from index_test where id1=11111;
2097152 rows in set (3.00 sec)
mysql> select * from index_test where id2=11111;
2097152 rows in set (2.32 sec)
id1的profile是这样的:
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000080 |
| checking permissions | 0.000014 |
| Opening tables | 0.000024 |
| init | 0.000033 |
| System lock | 0.000015 |
| optimizing | 0.000018 |
| statistics | 0.035408 |
| p