对,从Explain种的key字段可以看到使用了联合索引.但是还是有点区别的.我根据你的示例建了一个表.
CREATE TABLE `t1` (
`test_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(10) NOT NULL,
`age` int(11) NOT NULL,,
KEY `idx_id_name_age` (`test_id`,`name`,`age`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
执行explain select * from t1 where test_id = 2 and age = 2结果
+----+-------------+-------+------+-----------------+-----------------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+-----------------+-----------------+---------+-------+------+-------------+
| 1 | SIMPLE | t1 | ref | idx_id_name_age | idx_id_name_age | 4 | const | 1 | Using where |
+----+-------------+-------+------+-----------------+-----------------+---------+-------+------+-------------+
执行explain select * from t1 where test_id = 2 and name='xxxxx';的结果
+----+-------------+-------+------+-----------------+-----------------+---------+-------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+-----------------+-----------------+---------+-------------+------+-------------+
| 1 | SIMPLE | t1 | ref | idx_id_name_age | idx_id_name_age | 16 | const,const | 1 | Using where |
+----+-------------+-------+------+-----------------+-----------------+---------+-------------+------+-------------+
虽然key字段都是idx_id_name_age,但是在key_len字段第一个为4,但是第二个为16,说明第一个只使用了id作为索引,并没有使用联合索引.第二个字段才使用了联合索引.
也就是说idx_id_name_age(id,name,age)实际上只有三个索引,不包含(nam,age)索引.