{"id":44012,"date":"2022-08-18T08:00:00","date_gmt":"2022-08-18T15:00:00","guid":{"rendered":"https:\/\/www.microsoft.com\/en-us\/sql-server\/blog\/?p=44012"},"modified":"2024-04-19T10:39:24","modified_gmt":"2024-04-19T17:39:24","slug":"query-store-is-enabled-by-default-in-sql-server-2022","status":"publish","type":"post","link":"https:\/\/www.microsoft.com\/en-us\/sql-server\/blog\/2022\/08\/18\/query-store-is-enabled-by-default-in-sql-server-2022\/","title":{"rendered":"Query Store is enabled by default in SQL Server 2022"},"content":{"rendered":"\n
Part of the SQL Server 2022 blog series<\/a>.<\/em><\/p>\n\n\n\n Query Store<\/a> is one of the most powerful database-scoped features in SQL Server for troubleshooting performance and improving the stability of your database workloads.<\/p>\n\n\n\n The Query Store feature first became available in SQL Server 2016 and provides the ability for database administrators (DBAs) to gain insights on query plan choice and the impact these choices have on SQL Server performance.<\/p>\n\n\n\n In SQL Server 2022<\/a>, Query Store is now enabled by default for all newly created SQL Server databases to help customers better track performance history, troubleshoot query plan\u2013related issues, and enable new query processor capabilities that we will introduce in the subsequent SQL Server 2022 blog series<\/a>.<\/p>\n\n\n\n When enabled, Query Store asynchronously captures a history of queries, plans, and runtime statistics, and persists this data at the database scope. This means that when you migrate your databases to another version of SQL Server, migrate to different hardware, or even migrate your databases to the cloud\u2014you can examine the performance difference down to the query plan level.<\/p>\n\n\n\n Query Store accomplishes this by separating the performance data by time windows so DBAs can identify usage patterns and understand when query plan changes happened on the server.<\/p>\n\n\n\n If an application starts having a performance issue which can occur in a number of scenarios such as high usage, post-migration, and especially when data distributions change\u2014Query Store provides a method to force which plan a query will use<\/a>. The ability to control which plans a query will use makes it much easier to respond to errant query plans and provides database administrators with the assurance they can upgrade to later versions of SQL Server, change database compatibility levels, and confidently migrate database applications to the cloud. <\/p>\n\n\n\n For all these scenarios, Query Store gives DBAs the confidence that they can easily monitor their database application\u2019s performance and quickly respond to performance issues when needed.<\/p>\n\n\n\n Query Store is available for SQL Server, Azure SQL Database, Azure SQL Managed Instance, and Azure Synapse Analytics. In Azure SQL database, Query Store is referred to as Query Performance Insights<\/a> and is managed on the Query Performance Insight navigation blade.<\/p>\n\n\n\n While it is a new scenario to have Query Store enabled by default for SQL Server, Query Store has be enabled by default for Azure SQL Database<\/a> (including elastic pools<\/a>) and Azure SQL Managed Instance<\/a> databases for some time now and this capability has been extended to SQL Server 2022.<\/p>\n\n\n\n Query Store has been a popular feature since it was first made available in SQL Server 2016, and now in SQL Server 2022 we are leveraging Query Store\u2019s ability to persist query plan history and health to enable new capabilities.<\/p>\n\n\n\n Query Store in SQL Server 2022 extends the ability of the query processor by enabling features such as Query Store hints, cardinality estimation (CE) feedback, degree of parallelism (DOP) feedback, memory grant feedback (MGF) persistence, and optimized plan forcing.<\/p>\n\n\n\n Query Store\u2019s ability to asynchronously make a record of your database application\u2019s performance data enables these new capabilities in SQL Server 2022.<\/p>\n\n\n\n While we are enabling Query Store by default for all newly created databases in SQL Server 2022, it is important to note that for all databases that have been restored from other SQL Server instances and for those databases that are upgraded from an in-place upgrade to SQL Server 2022, these databases will retain the previous Query Store settings\u2014whether they had Query Store enabled or not.<\/p>\n\n\n\n As a post-migration step, for databases that are restored from previous SQL Server instances, it is recommended to enable Query Store<\/a> and separately evaluate the database compatibility level<\/a> settings as some Intelligent Query Processing features<\/a> are enabled by the compatibility level setting.<\/p>\n\n\n\n Note: <\/strong>For optimal SQL Server performance and migration health, it is recommended to closely follow the recommendations provided in the post-migration validation and optimization guide<\/a>.<\/p>\n\n\n\n As mentioned, Query Store has been available in Azure SQL Database and Azure SQL Managed Instance since 2016; additionally, we have improved Query Store performance in the last several releases of SQL Server with many improvements being surfaced through cumulative updates<\/a> in SQL Server 2019.<\/p>\n\n\n\n Microsoft has improved ad-hoc workloads with Query Store with several cumulative updates in SQL Server 2019.<\/p>\n\n\n\n The most relevant cumulative updates that influence Query Store health are:<\/p>\n\n\n\n Note:<\/strong> It is always recommended to evaluate the latest cumulative updates for the release of SQL Server your organization is maintaining for the best performance and stability of your database application environment.<\/p>\n\n\n\n In addition to the stability improvements, we introduced via the cumulative updates in SQL Server 2019, the Query Store default behavior has been refined to reduce the volume of the captured Query Store details while increasing the amount of Query Store history that can be retained.<\/p>\n\n\n\n The setting changes that were introduced in SQL Server 2019 have been carried forward and will improve the performance of the Query Store behavior while still optimizing the Query Store\u2019s ability to serve both as a \u201cflight data recorder,\u201d but to also enable the query processor\u2019s ability to leverage new capabilities in SQL Server 2022.<\/p>\n\n\n\n To improve the performance of the Query Store settings, the capture mode has changed from ALL to AUTO, and the max size (MB) has changed from 100 MB to 1024 MB.<\/p>\n\n\n\n Under the AUTO capture mode setting, we now capture Query Store details when any of the following thresholds are hit:<\/p>\n\n\n\n These settings help further reduce any impact Query Store could have on SQL Server, while still ensuring that the critical data is captured for troubleshooting and providing the ability to enable new capabilities in SQL Server 2022.<\/p>\n\n\n\n In order to take advantage of certain SQL Server 2022 capabilities, it is necessary to have Query Store enabled by default.<\/p>\n\n\n\n If there is still any concern about the overhead Query Store may introduce, database administrators can leverage custom capture policies<\/a> to further tune the Query Store capture behavior.<\/p>\n\n\n\n Custom capture policies are available to help further tune Query Store captures. Custom capture policies can be used to be more selective about which queries and query details are captured. For example, an administrator may choose to capture only the most expensive queries, repeated queries, or queries that have a high level of compute overhead.<\/p>\n\n\n\n Custom capture policies can help Query Store capture the most important queries in your workload.<\/p>\n\n\n\n Please see the example Note:<\/strong> Except for Query Store in SQL Server has been a popular feature since the SQL Server 2016 release to provide the ability for Query Store to act as a \u201cflight data recorder\u201d for SQL Server. Query Store accomplishes this by collecting information about query performance over time. As a result, Query Store has a strong capability to reduce the time it takes for a database administrator to respond to critical performance events and help ease the migration of databases between on-premises systems (hardware and SQL Server releases) as well as migrate database applications to the cloud.<\/p>\n\n\n\n DBAs use Query Store in many of the following scenarios<\/a> to:<\/p>\n\n\n\n SQL Server 2022 now supports the enabled by default behavior and introduces the ability for the Query Processor to be able to leverage the historical performance data.<\/p>\n\n\n\n This capability extends Query Store\u2019s power beyond troubleshooting and migration scenarios, and to the next level of intelligent query processing behavior in SQL Server.<\/p>\n\n\n\n Download the latest release<\/a> of SQL Server 2022 if you haven\u2019t already done so and check out the SQL Server 2022 Overview and What\u2019s New references. There are many new features and improved functionality being added to this release.<\/p>\n\n\n\n For more information and to get started, check out the following references:<\/p>\n\n\n\n Read What\u2019s New in SQL Server 2022<\/a>.<\/p>\n\n\n\n Additional useful resources:<\/p>\n\n\n\n In SQL Server 2022, Query Store is now enabled by default for all newly created SQL Server databases.<\/p>\n","protected":false},"author":6051,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"_classifai_error":"","footnotes":""},"post_tag":[5278],"product":[5227,3645],"content-type":[2448],"topic":[],"coauthors":[5093],"class_list":["post-44012","post","type-post","status-publish","format-standard","hentry","tag-sql-server-2022-blogging-series","product-sql","product-sql-server-2022","content-type-updates","review-flag-1593580427-503","review-flag-1-1593580431-15","review-flag-6-1593580457-144","review-flag-8-1593580467-480","review-flag-9-1593580472-173","review-flag-alway-1593580309-407","review-flag-lever-1593580264-545","review-flag-new-1593580247-437"],"yoast_head":"\nQuery Performance Insights in Azure SQL Database<\/h2>\n\n\n\n
Query Store overhead<\/h2>\n\n\n\n
Query Store improvements introduced via cumulative updates<\/h3>\n\n\n\n
\n
READ_ONLY<\/code> until enough memory has been returned to the Database Engine, preventing performance issues.<\/li>\n\n\n\n
FORCED <\/code>in the
ALTER DB <\/code>command. The
FORCED<\/code> option allows you to turn off Query Store immediately by aborting all background tasks.
ALTER DATABASE {0} SET QUERY_STORE = OFF (FORCED)<\/code><\/li>\n<\/ul>\n\n\n\n
Query Store setting improvements<\/h3>\n\n\n\n
\n
Custom capture policies<\/h3>\n\n\n\n
ALTER DATABASE<\/code> script below that would enable a custom capture policy for Query Store:<\/p>\n\n\n
\nALTER DATABASE [QueryStoreDB]\n SET QUERY_STORE = ON\n (\n OPERATION_MODE = READ_WRITE,\n CLEANUP_POLICY = ( STALE_QUERY_THRESHOLD_DAYS = 90 ),\n DATA_FLUSH_INTERVAL_SECONDS = 900,\n MAX_STORAGE_SIZE_MB = 1000,\n INTERVAL_LENGTH_MINUTES = 60,\n SIZE_BASED_CLEANUP_MODE = AUTO,\n MAX_PLANS_PER_QUERY = 200,\n WAIT_STATS_CAPTURE_MODE = ON,\n QUERY_CAPTURE_MODE = CUSTOM,\n QUERY_CAPTURE_POLICY = (\n STALE_CAPTURE_POLICY_THRESHOLD = 24 HOURS,\n EXECUTION_COUNT = 30,\n TOTAL_COMPILE_CPU_TIME_MS = 1000,\n TOTAL_EXECUTION_CPU_TIME_MS = 100\n ) );\n<\/pre><\/div>\n\n\n
STALE_CAPTURE_POLICY_THRESHOLD<\/code>, these options define the OR conditions that need to happen for queries to be captured in the defined Stale Capture Policy Threshold value.<\/p>\n\n\n
\nQUERY_CAPTURE_MODE = CUSTOM,\n QUERY_CAPTURE_POLICY = ( \nSTALE_CAPTURE_POLICY_THRESHOLD = 24 HOURS, \nEXECUTION_COUNT = 30, \nTOTAL_COMPILE_CPU_TIME_MS = 1000, \nTOTAL_EXECUTION_CPU_TIME_MS = 100 \n)\n<\/pre><\/div>\n\n\n
Summary<\/h2>\n\n\n\n
\n
Next steps<\/h2>\n\n\n\n
Learn more<\/h2>\n\n\n\n
\n