假设如下:
/*
drop index ix_vouchers_nacsz on dbo.vouchers;
drop index ix_vouchers_nacsz2 on dbo.vouchers;
create index ix_vouchers_nacsz on dbo.Vouchers(
FirstName, LastName,
Address, Address2, City,
State, Zip, Email
);
create index ix_vouchers_nacsz2 on dbo.Vouchers(
Email, FirstName, LastName,
Address, Address2, City,
State, Zip
);
*/
select count(firstname) from vouchers
with (index(ix_vouchers_nacsz))
where
firstname = 'chris' and
lastname = '' and
address = '' and
address2 = '' and
city = '' and
state = '' and
zip = ''
select count(firstname) from vouchers
with (index(ix_vouchers_nacsz2))
where
firstname = 'chris' and
lastname = '' and
address = '' and
address2 = '' and
city = '' and
state = '' and
zip = ''
为什么第二个索引会导致索引扫描,而第一个索引会导致索引查找?键的顺序有什么不同?