假设如下:的SQL Server索引的使用问题
/*
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 = ''
为什么第二索引的结果索引扫描,而在指数第一的成绩求?密钥的排序有什么不同?
好的一点,是的,在索引中包含“电子邮件”列是从来没有使用的呈现它对这个查询 – 2009-08-10 05:38:37
我没有使用电子邮件列另一个查询。我将它添加到这个索引中,希望这两个查询都可以使用它,而不是有两个大的索引。我应该创建两个索引吗? – Chris 2009-08-10 05:52:41
根据问题中的信息,我会在(名字,姓氏)和(电子邮件)上创建两个索引。这些索引几乎应该唯一标识一行。 – Andomar 2009-08-10 06:12:07