Saturday, June 5, 2021

Find Your Database's Query Store Settings

SQL query that pulls data from the sys.database_query_store_options view.

This query is likely related to monitoring or troubleshooting the SQL Server Query Store settings.

Here's a quick breakdown of the query:


SELECT
  actual_state_desc,               -- Description of the current state of the Query Store
  desired_state_desc,              -- Description of the desired state of the Query Store
  interval_length_minutes,         -- The length of the interval in minutes for Query Store data collection
  current_storage_size_mb,         -- The current size of the Query Store in MB
  max_storage_size_mb,             -- The maximum storage size for the Query Store in MB
  query_capture_mode_desc,         -- The capture mode for query plans and runtime statistics
  size_based_cleanup_mode_desc     -- The cleanup mode used when managing Query Store size
FROM sys.database_query_store_options WITH (NOLOCK)
OPTION (RECOMPILE);

Key Points:

  • WITH (NOLOCK): This hint tells SQL Server to perform a dirty read, meaning it doesn't acquire shared locks and can read uncommitted data. This can speed up queries but might return inconsistent results if data is being modified.
  • OPTION (RECOMPILE): Forces SQL Server to recompile the query plan each time it's run, which could be useful for queries with varying parameters but may add overhead.

Popular Posts