Or ‘How to really slow a query down without trying’
Here’s a query that looks innocent enough. Table structure and sample data are at the end of the post.
-- returns 5 out of 5000 rows SELECT InsertDate FROM TestingFunction WHERE LEFT(Code,1)='AA'
Knowing that there’s an index on the column code, the optimiser might be expected to use an index seek to satisfy the query. However, the execution plan shows an index scan. Why?