Understanding Scans And Seeks

How to Get the Best Out of Seek

In the last example, if we replace “ProductID / 3 = 0″ with “ProductID < 3″ the
operation will be faster as it enables SQL Server to identify the end of the search.

SELECT/span> TransactionID
FROM Production.TransactionHistory
WHERE TransactionID >= 100000 AND TransactionID <= 100100

SELECT TransactionID
FROM Production.TransactionHistory
WHERE TransactionID IN (100000,100001,100002,100003,100004,100005,100006,100007,100008,100009,100010,100011,100012,100013,

When the second query is used, because there are many distinct values to be searched, SQL Server creates a constant list and executes the seek operation for each constant once. That generates 101 executions of the seek operation where the first query simply returns the rows in a single pass. Even though both are seek operations we may be able to reduce the total cost drastically.

(397 row(s) affected)
Table 'TransactionHistory'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0

(1 row(s) affected)

(397 row(s) affected)
Table 'TransactionHistory'. Scan count 99, logical reads 228, physical reads 0, read-ahead reads 0

(1 row(s) affected)


·      The Scan operation reads either from beginning or from the end of the object, whereas Seek starts at a particular location in the object.

·      Both Seek and Scan continue their operation until either the conditions are met or the entire object is scanned.

·      Even though Seek is considered as a better option than scan, it should be analyzed based on the query and the data involved.

Pages: 1 2 3


No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |