質問

I have a query like below

    Select top(10) *
    from myTable
    where CreateTime between '2014-2-3' and '2014-2-5' 
    and (Result is null or Result != 1) 

But when i build an index like below

    CREATE NONCLUSTERED INDEX [IX_Index] ON [dbo].[mytable] 
    (
[CreateTime] ASC,
    Result ASC
    )
    INCLUDE ( [ID])

([ID] is primary Key of mytable)

Sql server does not use that index

how can i speed up above query?

役に立ちましたか?

解決 2

Try to simply build the index like

CREATE NONCLUSTERED INDEX [IX_Index] ON [dbo].[mytable] 
(
   [CreateTime]
)

Since you are filtering on CreateTime, just build a covering index on that column. I don't think that adding Result to the index will help the query.

Also you don't have to include the primary key column in the index, SQL Server does that automatically.

他のヒント

Try to use if you want to force sql server to use specific index.

Select top(10) *
from myTable WITH (INDEX(IX_Index))
where CreateTime between '2014-2-3' and '2014-2-5' 
and (Result is null or Result != 1) 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top