I have the following very large table in SQL Server 2005:
create table Blah ( FirstName varchar(30), Rank int, Position int, ... )
I will run the following query on it:
declare @PassedInFirstName varchar(30) set @PassedInFirstName = 'SomeName' select TOP 1 Position from Blah where FirstName = @PassedInFirstName order by Rank DESC
I am setting up the following index on it:
CREATE INDEX IX_Blah ON Blah (FirstName, Rank)
Given that I order it by Rank DESC, should I change the index to order Rank in a descending way:
CREATE INDEX IX_Blah ON Blah (FirstName ASC, Rank DESC)
Or it does not matter?
Thanks.
If should benefit if the WHERE returns many rows.
I’ve seen results where logical IO was reduced by 50% by using DESC in the INDEX to match an ORDER BY
Also, change the query to covering:
SQL 2005 +:
SQL 2000, SQL 7: