'Why the indexes not speeding up the query?

I have the following query:

SELECT TOP 1000 * 
FROM MyTable 
WHERE Status = 'N' AND Type is not null 
ORDER BY mytable.id

MyTable has 130 million rows.

I also created these indexes:

CREATE INDEX "MyTableIndex_1" ON MyTable (Status);
CREATE INDEX "MyTableIndex_2" ON MyTable (Type);

The ID column was already a clustered index.

Somehow the query is still very slow. What am I missing?



Solution 1:[1]

try a multi column index

CREATE INDEX "MyTableIndex_StatusType" ON MyTable (Status, Type);

if that doesn't work then do some research on 'Covering Indexes'

Solution 2:[2]

Type is not null , the index on this column might not help.

BTW, can you try update index statistics before the query?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 spender
Solution 2 SeanH