Contents
What is table scan and index scan?
An index scan or table scan is when SQL Server has to scan the data or index pages to find the appropriate records. A scan is the opposite of a seek, where a seek uses the index to pinpoint the records that are needed to satisfy the query. Here we can see that this query is doing a Clustered Index Scan.
What is table scan in database?
A table scan is the reading of every row in a table and is caused by queries that don’t properly use indexes. Table scans on large tables take an excessive amount of time and cause performance problems.
Why does SQL Server not use index scan?
If your query is returning too many rows, a high percentage of the total rows in the table, SQL Server will not use the index. This happens because the cost of the key lookup for each row can be bigger than the cost of an entire scan.
What does the SQL execution plan look like?
If you execute the previous SELECT query, including the Actual Execution Plan, the generated plan in our case will be like: It is clear from the generated plan, that the SQL Server Engine scans all the table rows (100K records) to retrieve the requested data (1 record).
When to use clustered index or table scan?
Here we can see that this query is doing a Table Scan, so when a table has a Clustered Index it will do a Clustered Index Scan and when the table does not have a clustered index it will do a Table Scan. Since this table does not have a clustered index and there is not a WHERE clause SQL Server scans the entire table to return all rows.
What does it mean to scan an index?
An index scan means that all the leaf-level of the index was searched to find the information for the query: When the index is a clustered index, this is the same as scanning the entire table. With only a few exceptions, this isn’t good; we need to try to turn scans into seeks, which means retrieving the data by just using the index tree.