November 21, 2017 at 3:17 am
In SQL server 2008R2, Table having Non-clustered index and table contains 2 crore records, while executing "Select count(*) from table name" it going for table scan, its not using non clustered index. Why index is not used?
November 21, 2017 at 3:22 am
It's going to have to scan something, since there's no filter on that query. Optimiser calculated that a scan of the table will be the most efficient.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 21, 2017 at 3:33 am
If any where condition is there, optimizer would use Non-clustered index right?
November 21, 2017 at 3:47 am
Maybe. Depends on the predicate, the index key columns and the rest of the query. It's not as simple as you're making out.
There's a lot of posts on indexes and index usage on my blog. https://www.sqlinthewild.co.za/index.php/category/sql-server/indexes/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 22, 2017 at 8:25 am
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply