Home Simple Select Query taking long time to execute
Reply: 1

Simple Select Query taking long time to execute

Faisal
1#
Faisal Published in 2017-11-14 07:46:48Z
select id, subject, date, source 
from TABLE_NAME 
where source = 'ABC' 
order by date desc

The above query fetches only 917 rows (out of 300,000 rows), but needs almost 3 minutes

What could be the problem?

Jayasurya Satheesh
2#
Jayasurya Satheesh Reply to 2017-11-14 08:50:29Z

This may occur if your table is not properly indexed. Since you are filtering 917 out of 300000 records, if the column "Source" that you are searching is not indexed, then the Database Engine had to search from the Start to End to find the matching values. Try adding a Non-Clustered Index on the column - If you already have one Clustered index on any other column on the same table.

Refer the below links for more details on Indexing

Understanding SQL Server Indexing - mssqltips.com

SQL Server Indexes Tutorial - SQL Server Planet

Indexes in MS SQL Server - Code Project

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309435 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO