Professional Documents
Culture Documents
How To Troubleshoot A Slow Running Query in SQL Server
How To Troubleshoot A Slow Running Query in SQL Server
Question: Usually when I look at the statistics information on an index, SQL statistics are available.
I was troubleshooting a query performance issue today – and noticed no statistics under heavily used
objects. What could be causing this problem, as I understand the DB engine maintains the statistics
about the key value distribution, and uses the statistics for query plan compilation?
Answer: Check the status of AUTO CREATE STATISTICS. If it’s OFF, then most likely someone
has turned it off. When AUTO CREATE STATISTICS is set at OFF, a manual process must be set up
to create statistics.
Normally I have AUTO CREATE STATISTICS at ON. This means the SQL Query Optimizer creates
the statistics on individual columns for cardinality improvement.
View HYPERLINK "http://www.sqlserver-dba.com/2012/08/sql-server-auto-create-statistics.html" source
3.
sys.dm_exec_query_optimizer_info – displays information about the SQL Server query optimizer.
Use it for workload tuning process
It is possible to force the Optimizer to use a plan. Use USE PLAN to pass a query plan to the
Optimizer. USE PLAN will force the plan to use and override the Optimizer. Typically used in an
upgrade , where the later version of SQL Server optimizer does not return query plans as expected.
Maintaining statistics is critical to accurate execution plans. If the data in the statistics objects is
inaccurate the Optimizer will use an inefficient execution plan. DBCC SHOW_STATISTICS,
sys.dm_exec_query_optimizer_info, and USE PLAN are three ways of exploring and maximizing the
Optimizer