有下表
create table a1
{
id int(11) not null,
name varchar(32) not null,
age int(11) not null,
INDEX (id,name)
}
下面查询中,索引无效的有(A)。
A. select * from a1 where name = ‘Jack’;
B. select * from a1 where name != ‘Jack’;
C. select * from a1 where id = 1 and name like ‘J%’;
D. select * from a1 where id <> 1
为什么BD是有效的?
真正索引有效的只有 C, 不知你的题是出自何处, 更有可能的是题目搞错了.
AB 完全用不到联合索引,因为索引是按记录顺序查找到的,name 在 id 后面, 无法不查 id 直接用 name查询.
创建表和数据
分析索引
作为比较, 可以看一下下面的结果
如查返回结果
type=ALL
则意味着全表扫描, 有无索引已没太大意义.