Database Management
Query Plan Was Not Collected in SQL Sentry
This article describes some common reasons why a query plan match may not have been found for a specific batch or statement in SQL Sentry.
First published date
Last published date
Overview
Product section
Cause
Why was a query plan not collected?
Resolution
Dynamic SQL
EXEC ('tsql_string')andsp_executesqldo not compile queries until execution.- The only way to gather the plan is to capture the plan handle while the query is running.
- The default polling interval is 5 seconds; the plan may not be captured if the dynamic SQL runs faster.
Batches with More Than One Statement
- Retrieving a plan sometimes requires
SET SHOWPLAN_XML ON. - SQL Sentry does not capture plans this way for batches with multiple statements to avoid plan cache bloat.
- If the batch runs many
Matching Errors
- Plan analysis can fail due to race conditions within SQL Server DMVs (
dm_exec_requests,dm_exec_query_stats). - These DMVs pull data from multiple sources, which may not always be consistent, causing matching errors and preventing plan matches.
Encrypted Stored Procedures
- Encrypted stored procedures do not return meaningful query plan data.
- Since query plans reveal statements, encrypted plans hide this information by design.
Unavailable System Stored Procedures
- Some system-stored procedures are hidden, which can cause issues.
- Capturing the handle during execution may retrieve the plan, but object or plan lookups might not yield valid plan information.
Trivial Plans
- Some plans are trivial and contain only statements that do not generate plan information. For instance, the following statement will never generate a query plan:
IF (1 = 1)
WAITFOR DELAY '00:00:10'
Plan Eviction
- Under memory pressure, SQL Server may evict plans from the cache to free memory.
- The plan will be unavailable if a plan is evicted between SQL Sentry capturing the query and plan collection.
- Manual cache clearing via
DBCC FREEPROCCACHEcan also cause this.
Very Large Plans
-
Execution plans larger than 4MB may not be matched due to SQL Server function limitations in gathering plan XML.
-
SQL Sentry versions 6.2.60.0 and higher include a configuration option to mitigate this issue:
To enable the mitigation:
- Locate
SQLSentryServer.exe.configin the SQL Sentry Monitoring Service install directory. - Open the file in a text editor.
- Find the
<appSettings>XML element. - Add the following key inside
<appSettings>(following the existing format):
add key="useTextBasedQueryPlanFunction" value="true"
- Save the file.
- Restart the SQL Sentry Monitoring Service.
Optimize For Ad Hoc Workloads Enabled
- When "optimize for ad hoc workloads" is enabled on SQL Server, ad hoc plans are not cached until used more than once.
- Only a plan stub is stored initially, which means no full plan is available to capture.
- SQL Sentry cannot match SQL events with plans if only stubs exist.