Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Introducing Microsoft SQL Server 2019

You're reading from  Introducing Microsoft SQL Server 2019

Product type Book
Published in Apr 2020
Publisher Packt
ISBN-13 9781838826215
Pages 488 pages
Edition 1st Edition
Languages
Authors (8):
Kellyn Gorman Kellyn Gorman
Profile icon Kellyn Gorman
Allan Hirt Allan Hirt
Profile icon Allan Hirt
Dave Noderer Dave Noderer
Profile icon Dave Noderer
Mitchell Pearson Mitchell Pearson
Profile icon Mitchell Pearson
James Rowland-Jones James Rowland-Jones
Profile icon James Rowland-Jones
Dustin Ryan Dustin Ryan
Profile icon Dustin Ryan
Arun Sirpal Arun Sirpal
Profile icon Arun Sirpal
Buck Woody Buck Woody
Profile icon Buck Woody
View More author details
Toc

Table of Contents (15) Chapters close

Preface 1. Optimizing for performance, scalability and real‑time insights 2. Enterprise Security 3. High Availability and Disaster Recovery 4. Hybrid Features – SQL Server and Microsoft Azure 5. SQL Server 2019 on Linux 6. SQL Server 2019 in Containers and Kubernetes 7. Data Virtualization 8. Machine Learning Services Extensibility Framework 9. SQL Server 2019 Big Data Clusters 10. Enhancing the Developer Experience 11. Data Warehousing 12. Analysis Services 13. Power BI Report Server 14. Modernization to the Azure Cloud

Query Store

The Query Store in SQL Server, first introduced in SQL Server 2016, streamlines the process of troubleshooting query execution plans. The Query Store, once enabled, automatically captures query execution plans and runtime statistics for your analysis. You can then use the sys.dm_db_tuning_recommendations view to discover where query execution plan regression has occurred and use the stored procedure, sp_query_store_force_plan, to force a specific plan that performs better.

In SQL Server 2019, we now have made some additional enhancements to the default Query Store features. In this section, we will discuss the following topics:

  • Changes to default parameter values when enabling Query Store
  • A new QUERY_CAPTURE_MODE custom
  • Support for fast forward and static cursors

You can configure Query Store with SQL Server Management Studio (SSMS) or with T-SQL statements. SSMS configuration includes turning it on and off by setting the operation mode (off, read-only, or read/write), the Query Store size, and other settings. You can find Query Store parameters in the properties of a database by right-clicking on the database and selecting Query Store:

Figure 1.16: Database properties dialogue window
Figure 1.16: Database properties dialogue window

Changes to default parameter values

Two of the existing parameters have new default values compared to SQL Server 2017. These parameters are MAX_STORAGE_SIZE_MB and QUERY_CAPTURE_MODE. The new default values as of SQL Server 2019 are listed here:

  • MAX_STORAGE_SIZE_MB has a default value of 1000 (MB)
  • The QUERY_CAPTURE_MODE has a default value of AUTdO

QUERY_CAPTURE_MODE

In previous versions of SQL Server, the default value for the QUERY_CAPTURE_MODE was set to ALL, and therefore all query plans were captured and stored. As mentioned in the previous section, the default value has now been changed to AUTO.

Setting the QUERY_CAPTURE_MODE to AUTO means that no query plans or associated runtime statistics will be captured for the first 29 executions in a single day. Query plans and runtime statistics are not captured until the 30th execution of a plan. This default setting can be changed by using the new custom mode.

QUERY_CAPTURE_MODE: CUSTOM

Before 2019, there were three available values for the query_capture_mode; those values were NONE, ALL, and AUTO. We have now added a fourth option, which is CUSTOM.

The CUSTOM mode provides you with a mechanism for changing the default settings of the Query Store. For example, the following settings can be modified when working in CUSTOM mode:

  • EXECUTION_COUNT
  • TOTAL_COMPILE_CPU_TIME_MS
  • TOTAL_EXECUTION_CPU_TIME_MS
  • STALE_CAPTURE_POLICY_THRESHOLD

First, you can verify and validate the current Query Store settings by using the sys.database_query_store_options view:

SELECT actual_state_desc, stale_query_threshold_days, query_capture_mode_desc, 
  capture_policy_execution_count, capture_policy_total_compile_cpu_time_ms, 
  capture_policy_total_execution_cpu_time_ms 
FROM sys.database_query_store_options

The output is as follows:

Figure 1.17: Verifying and validating the Query Store settings
Figure 1.17: Verifying and validating the Query Store settings

To modify the default settings, you will first change the query capture mode to custom and then apply changes to the default values. Look at the following code by way of an example:

ALTER DATABASE AdventureWorks2017 
SET QUERY_STORE = ON
(
  QUERY_CAPTURE_MODE = CUSTOM, QUERY_CAPTURE_POLICY =
  (
    EXECUTION_COUNT = 20,
    TOTAL_COMPILE_CPU_TIME_MS = 1000,
    TOTAL_EXECUTION_CPU_TIME_MS = 100,
    STALE_CAPTURE_POLICY_THRESHOLD = 7 DAYS
  )
);

The output is as follows:

Figure 1.18: Modifying the default settings
Figure 1.18: Modifying the default settings

Support for FAST_FORWARD and STATIC Cursors

We have added another exciting update to the Query Store. You can now force query execution plans for fast forward and static cursors. This functionality supports T-SQL and API cursors. Forcing execution plans for fast forward and static cursors is supported through SSMS or T-SQL using sp_query_store_force_plan.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime