Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Imagine Foo table has non-clustered indexes on ColA and ColB and NO Indexes on ColC, ColD
SQL
SELECT colA, colB
FROM Foo

takes about 30 seconds.
SQL
SELECT colA, colB, colC, colD
FROM Foo

takes about 2 minutes.
Foo table has more than 5 million rows.
Question: Is it possible that including columns that are not part of the indexes can slow down the query? If yes, WHY? -Are not they part of the already read PAGEs?
Posted

You can improve the performace by creating multiple index with different combinations of columns as per the need. The other option is if you want to fetch the columns let's say colB, colC, colD only based on colA index then you can use include while creating the index as shown in the example.

SQL
CREATE NONCLUSTERED INDEX IX_INDEX1    ON Foo (colA)
    INCLUDE (colB, colC, colD);


And also look at the execution plan to identify the bottelnecks. For more details about creating index try this link http://msdn.microsoft.com/en-us/library/ms188783.aspx[^]

Hope this is useful.
 
Share this answer
 
v2
Comments
damodara naidu betha 28-Jun-13 1:31am    
5+
Clustered indexes are stored along with data while non-clustered indexes are not. Mixing them in SELECT statement is never a smart choice.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900