concept table scan in category sql

appears as: table scs, table sc, table sc
SQL Server DMVs in Action: Better Queries with Dynamic Management Views

This is an excerpt from Manning's book SQL Server DMVs in Action: Better Queries with Dynamic Management Views.

In addition to investigating the area identified as being the mostly costly, you can also check the cached plan for indicators of potential performance problems. These indicators include table scans, missing indexes, columns without statistics, implicit data type conversions, unnecessary sorting, and unnecessary complexity. We’ll provide a SQL query later in the book that will allow you to search for these items that may be the cause of poor performance.

The script used to discover SQL queries that contain table scans is essentially the same as that used to find queries that have missing statistics (discussed previously), but the LIKE clause needs to be replaced with the following:

LIKE '%<TableScan%'

For relatively small tables, the optimizer may decide it’s cheaper to scan the table than to use an index. A missing index or inappropriate indexes might also cause the optimizer to use table scans. As an example of an inappropriate index, if a query needs to retrieve a lot of data, some of which it can get from an index and the rest from the underlying table, because it can be costly to repeatedly get the data from the underlying table via an index (key) lookup, it’s often more appropriate to bypass the index completely and scan the underlying table for the required data. To remedy this situation, it may be necessary to create a new index that contains the required data or consider adding the required columns as INCLUDEd columns on the index.

Searching the cached plans for table scans could prove useful in corroborating that indexes are missing or are of an inappropriate type. It may also catch inappropriate SELECT statements without a WHERE condition.