My database contains a specific table that is quite large (250+M rows, 100+GB data space).
Generating a clustered index scan on this table is always a bad idea.
This table has multiple indexes and we never run a query on this table without specifying predicates on indexed columns.
Since we updated the server, we have experienced random query plan degradations. Queries that would run in a few seconds randomly start to timeout after multiple dozens of minutes.
Here are the server changes:
- The compatibility level was updated from 2008 to 2016, thus the cardinality estimator changed.
- SQL Server edition was updated from Standard to Enterprise.
- SQL Server version (2016) was not changed.
- The storage (SSD) was not changed.
Of course, I can easily solve this issue for one specific query by adding hints, but I have too many queries in my applications to broadly apply this solution.
Is there a way to globally prevent SQL Server from generating Clustered Index Scan on this table?
I uploadedwas not able to reproduce the same bad query plans forfrom my previous production issues (the bad query plans happen randomly), but I was able to generate similar query plans using a new simple query. I uploaded plans for the simple query without hint and with hint.
OPTION (RECOMPILE)
could solve the issue. But it does not ensure that the new query plan will be better or that SQL Server will not switch to another query plan in a few days. I am not looking for a way to improve one particular query or to improve one particular query plan. I want to globally prevent Clustered Index Scan on my table.
I have many queries that query many different columns and I cannot include all columns in all indexes.
One global option that would probably solve my issues is to use the legacy cardinality estimator, but I hope to find something better.