SlideShare a Scribd company logo
Intro to Query Store
By Tracy Boggiano
Tracy Boggiano
SQL Server DBA for 20+
years
@TracyBoggiano
databasesuperhero.com
tracyboggiano
speakingmentors.com
• What It Can Do For Us?
• Setup
• How It Works
• Reports
• Usage Scenarios
• 2017 Features
• Troubleshooting
• Best Practices
Agenda
WHAT IT CAN DO FOR US?
What Query Store Can Do For Us?
• Regressed Queries
• Identify Top Consuming Queries
• Audit the history of query plans
• Identify Resource Consumption Patterns
What Query Store Can Do For Us?
• In 2017
• Wait Stats
• Automatic plan correction
• Show more statistics
• In 2019
• Show even more statistics
SETUP
Query Store Setup
• Run one simple command:
• ALTER DATABASE [DatabaseName]
SET QUERY_STORE = ON;
Query Store Options 2016+
• Operation Mode
• Data Flush Interval (Minutes)
• Statistics Collection Interval
• Max Size (MB)
• Query Store Capture Mode
• Size Based Cleanup Mode
• Stale Query Threshold (Days)
Query Store Options 2017
• Waits Statistics Capture
• Max Plans Per Query
Query Store Options 2019
• Query Store Capture Mode = CUSTOM
 Stale Capture Policy Threshold
 Execution Count
 Total Compile CPU Time MS
 Total Execution CPU Time MS
Query Store Setup
• PRIMARY filegroup
• https://feedback.azure.com/forums/90803
5-sql-server/suggestions/32902072-
option-to-store-query-store-data-in-a-
filegroup-ot
Query Store Setup
• Per Database
• Nice to have Central Repository
• https://feedback.azure.com/forums/9
08035-sql-
server/suggestions/33815995-create-
central-repository-for-query-store
Query Store Trace Flags
• 7745 - Forces Query Store to not flush
data to disk on database shutdown.
• 7752 - Enables asynchronous loading of
database
GUI
• Right click the
database, the
click on
properties,
then Query
Store
dbatools
• Get-DbaQueryStoreOptions
• Set-DbaQueryStoreOptions
• Copy-DbaQueryStoreOptions
Query Store Setup Summary
• Set your options especially size
• PRIMARY filegroup
• Per database
• Use CUSTOM if you have ad-hoc quereies
and are on 2019
HOW IT WORKS
How Query Store Collects
Information
• Query processed by Algebrizer and
sends it to the Query Optimizer
• Checks for forced plan or out pops
a new Execution Plan
• Query Plan is put into Plan Cache
• Async collects data into Query
Store Memory
• Async writes to disk
Where Query Store Collects Information
• Plan Store – query plan, query text, last execution time,
compile time
• Runtime Stats Store – all runtime stats for plans, cpu,
logical reads, logical writes, physical reads, memory,
tempdb, duration, execution count
• Wait Stats Store – wait categories per plan
Database Superhero 2018
REPORTS
Ways to Stabilize Perfomance
• Change code and/or schema
• Add RECOMPILE
• Manually get the best plan in the cache
• Use a plan guide
• Force a plan using query store
Regressed Queries
• Identify queries that have degraded in
performance
• See if there is plan that can be forced
easily
• Force the previous plan from the history
Regressed Queries
Regressed Queries
Check Status of Forced Queries
• Query = is_forced_plan = 1
• Look at report in SSMS
• Extended event
Overall Resource Consumption
Top Consuming Resources
• Look at forcing a plan because of regression
• Missing indexes
• Make sure that the statistics are up-to-date
• Make sure that indexes used by the query are
defragmented
• Consider rewriting expensive query
Queries with High Variation
Query Wait Statistics
Queries with Force Plans
REPORTS
DEMO
USAGE SCENARIOS
Forcing Query Plans Manually
• Using reports you can easily find queries
with multiple plans and force a plan
• They are not schema-bound
• Should monitor for failures with Extended
Events
• When manually forced the plan is used
even when it is no longer optimal
A/B Testing
• Rolling out new application version
• Adding new hardware to the server
• Creating missing indexes for expensive
queries
Upgrade SQL Server
Summary of Usage Scenarios
• Forcing Query Plans Manually
• A/B testing
• Upgrade SQL Server
Database Superhero 2018
2017 FEATURES
Wait Stats
• New DMV sys.query_store_wait_stats
• 23 categories
• Tracks by category of wait stats such as
CPU or MEMORY
Automatic Plan Correction
• Recommendations surfaced via
sys.dm_db_tuning_recommendations
• Can automatically switch to last known good
plan
• Data is in DMV even if you don’t have the
option turned on
• Data is lost on reboot of SQL Server
Automatic Plan Correction Setup
ALTER DATABASE CURRENT
SET AUTOMATIC_TUNING
(FORCE_LAST_GOOD_PLAN = ON);
Monitoring Automatic Plan Correction
• Create an Extended Events session that captures
automatic tuning events
• automatic_tuning_error
• automatic_tuning_plan_regression_detec
tion_check_completed
• automatic_tuning_plan_regression_verif
ication_check_completed
• automatic_tuning_recommendation_expire
d
Summary of 2017 Features
• Automatic Plan Correction
• Wait Stats
Auto Tuning
sp_BlitzQueryStore
DEMOS
TROUBLESHOOTING
Perfmon Counters
• Query Store CPU usage
• Query Store logical reads
• Query Store logical writes
• Query Store physical reads
Geek Sync | Intro to Query Store
Wait Stats
• Ton of these, they all start with qds
• Three can be safely ignored:
• qds_async_queue
• qds_cleanup_stale_queries_task_main_loop_sleep
• qds_shutdown_queue
• Use Paul Randal’s script is the best way to look at wait
stats
Extended Events
• Over 50 events added
• Most can only be used by special trace
flags for Microsoft troubleshooting
• We will look at script for the important
ones
BEST PRACTICES
Best Practices
• Manage the size
• Set you Statistics Interval
• Make sure it is continuing to collect data
• Avoid using non-parameterized queries
• Avoid using drop/create process
• Avoid renaming databases
Using the Query Store with In-Memory
OLTP
• Turn on runtime statistics collection with
sys.sp_xtp_control_query_exec_stats
• Need to reset on server restart or if you
clear Query Store
• Memory grants metrics are not kept
Things of Note
• Forced plans can fail
• Drop an index
• Change the name of an index
• Remove columns from an index
• Forced plans for do work on the secondaries
of your AGs
• Forced plans don’t age out of Query Store
Resources
• Monitoring Performance By Using the Query Store - https://docs.microsoft.com/en-
us/sql/relational-databases/performance/monitoring-performance-by-using-the-query-
store
• Best Practice with the Query Store - https://msdn.microsoft.com/en-
us/library/mt604821.aspx
• Wait Stats - https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-
views/sys-query-store-wait-stats-transact-sql
• Automatic plan correction in SQL Server 2017 -
https://blogs.msdn.microsoft.com/sqlserverstorageengine/2017/05/17/automatic-plan-
correction-in-sql-server-2017/
• T-SQL Tuesday #124 Summary - https://tracyboggiano.com/archive/2020/03/t-sql-
tuesday-124-query-store-summary/
• Erin Stellato’s Blog - https://www.sqlskills.com/blogs/erin/category/query-store/
• Grant Fritchey’s Blog - https://www.scarydba.com/?s=query+store
Contact Info
EMAIL
tracy@tracyboggiano.com
TWITTER
@TracyBoggiano
MY WEBSITE
databasesuperhero.com
Thank you!

More Related Content

What's hot (20)

PDF
Sybase BAM Overview
Xu Jiang
 
PPTX
Oct 2011 CHADNUG Presentation on Hadoop
Josh Patterson
 
PPTX
Data Warehouse Modernization - Big Data in the Cloud Success with Qubole on O...
Qubole
 
PPTX
Google cloud certification data engineer
Joseph Holbrook, Chief Learning Officer (CLO)
 
PPTX
Work with hundred of hot terabytes in JVMs
Malin Weiss
 
PPTX
Keynote – From MapReduce to Spark: An Ecosystem Evolves by Doug Cutting, Chie...
Cloudera, Inc.
 
PDF
Configuration Driven Reporting On Large Dataset Using Apache Spark
Databricks
 
PPTX
eBay Cloud CMS based on NOSQL
Xu Jiang
 
PPTX
What SharePoint Admins need to know about SQL-Cinncinati
J.D. Wade
 
PPTX
LeanXcale for Monitoring
LeanXcale
 
PPTX
What SQL DBA's need to know about SharePoint
J.D. Wade
 
PDF
Google Cloud Data Platform - Why Google for Data Analysis?
Andreas Raible
 
PDF
How to optimize asp dot-net application
sonia merchant
 
PDF
How Adobe uses Structured Streaming at Scale
Databricks
 
PDF
#GeodeSummit - Where Does Geode Fit in Modern System Architectures
PivotalOpenSourceHub
 
PPTX
Expert summit SQL Server 2016
Łukasz Grala
 
PPTX
Azure Data Factory Data Flow Performance Tuning 101
Mark Kromer
 
PPTX
Monitorando performance no Azure SQL Database
Vitor Fava
 
PPTX
Our Journey from Cassandra to Scylla
ScyllaDB
 
PPTX
Oracle dba online training in india usa canada
enrollmy training
 
Sybase BAM Overview
Xu Jiang
 
Oct 2011 CHADNUG Presentation on Hadoop
Josh Patterson
 
Data Warehouse Modernization - Big Data in the Cloud Success with Qubole on O...
Qubole
 
Google cloud certification data engineer
Joseph Holbrook, Chief Learning Officer (CLO)
 
Work with hundred of hot terabytes in JVMs
Malin Weiss
 
Keynote – From MapReduce to Spark: An Ecosystem Evolves by Doug Cutting, Chie...
Cloudera, Inc.
 
Configuration Driven Reporting On Large Dataset Using Apache Spark
Databricks
 
eBay Cloud CMS based on NOSQL
Xu Jiang
 
What SharePoint Admins need to know about SQL-Cinncinati
J.D. Wade
 
LeanXcale for Monitoring
LeanXcale
 
What SQL DBA's need to know about SharePoint
J.D. Wade
 
Google Cloud Data Platform - Why Google for Data Analysis?
Andreas Raible
 
How to optimize asp dot-net application
sonia merchant
 
How Adobe uses Structured Streaming at Scale
Databricks
 
#GeodeSummit - Where Does Geode Fit in Modern System Architectures
PivotalOpenSourceHub
 
Expert summit SQL Server 2016
Łukasz Grala
 
Azure Data Factory Data Flow Performance Tuning 101
Mark Kromer
 
Monitorando performance no Azure SQL Database
Vitor Fava
 
Our Journey from Cassandra to Scylla
ScyllaDB
 
Oracle dba online training in india usa canada
enrollmy training
 

Similar to Geek Sync | Intro to Query Store (20)

PPTX
SQL Server 2016 Query store
Vitaliy Popovych
 
PPTX
Query Store and live Query Statistics
SolidQ
 
PDF
Live Query Statistics & Query Store in SQL Server 2016
Antonios Chatzipavlis
 
PDF
Using Query Store to Understand and Control Query Performance
Grant Fritchey
 
PDF
SQL Server 2017 - Adaptive Query Processing and Automatic Query Tuning
Javier Villegas
 
PDF
Sql server 2016 rc 3 query store overview and architecture
Ahsan Kabir
 
PPTX
IDERA Live | Leverage the Query Store for Better SQL Server Performance
IDERA Software
 
PPTX
05_DP_300T00A_Optimize.pptx
KareemBullard1
 
PDF
Welcome To The 2016 Query Store!
SolarWinds
 
PDF
Redgate Community Circle: Tools For SQL Server Performance Tuning
Grant Fritchey
 
PDF
SQL Server Tools for Query Tuning
Grant Fritchey
 
PDF
SQL Server 2017 Enhancements You Need To Know
Quest
 
PDF
The Query Store SQL Tuning
Grant Fritchey
 
PPTX
Sql query analyzer & maintenance
nspyrenet
 
PPTX
SQL Query Optimization: Why Is It So Hard to Get Right?
Brent Ozar
 
PPTX
My Database Skills Killed the Server
ColdFusionConference
 
PPT
PASS Summit 2010 Keynote David DeWitt
GraySystemsLab
 
PPTX
IDERA Live | The Modern Query Optimizer
IDERA Software
 
PPTX
Sql killedserver
ColdFusionConference
 
PPTX
My SQL Skills Killed the Server
devObjective
 
SQL Server 2016 Query store
Vitaliy Popovych
 
Query Store and live Query Statistics
SolidQ
 
Live Query Statistics & Query Store in SQL Server 2016
Antonios Chatzipavlis
 
Using Query Store to Understand and Control Query Performance
Grant Fritchey
 
SQL Server 2017 - Adaptive Query Processing and Automatic Query Tuning
Javier Villegas
 
Sql server 2016 rc 3 query store overview and architecture
Ahsan Kabir
 
IDERA Live | Leverage the Query Store for Better SQL Server Performance
IDERA Software
 
05_DP_300T00A_Optimize.pptx
KareemBullard1
 
Welcome To The 2016 Query Store!
SolarWinds
 
Redgate Community Circle: Tools For SQL Server Performance Tuning
Grant Fritchey
 
SQL Server Tools for Query Tuning
Grant Fritchey
 
SQL Server 2017 Enhancements You Need To Know
Quest
 
The Query Store SQL Tuning
Grant Fritchey
 
Sql query analyzer & maintenance
nspyrenet
 
SQL Query Optimization: Why Is It So Hard to Get Right?
Brent Ozar
 
My Database Skills Killed the Server
ColdFusionConference
 
PASS Summit 2010 Keynote David DeWitt
GraySystemsLab
 
IDERA Live | The Modern Query Optimizer
IDERA Software
 
Sql killedserver
ColdFusionConference
 
My SQL Skills Killed the Server
devObjective
 
Ad

More from IDERA Software (20)

PPTX
The role of the database administrator (DBA) in 2020: Changes, challenges, an...
IDERA Software
 
PPTX
Problems and solutions for migrating databases to the cloud
IDERA Software
 
PPTX
Public cloud uses and limitations
IDERA Software
 
PPTX
Optimize the performance, cost, and value of databases.pptx
IDERA Software
 
PPTX
Monitor cloud database with SQL Diagnostic Manager for SQL Server
IDERA Software
 
PPTX
Database administrators (dbas) face increasing pressure to monitor databases
IDERA Software
 
PPTX
Six tips for cutting sql server licensing costs
IDERA Software
 
PDF
Idera live 2021: The Power of Abstraction by Steve Hoberman
IDERA Software
 
PDF
Idera live 2021: Why Data Lakes are Critical for AI, ML, and IoT By Brian Flug
IDERA Software
 
PDF
Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...
IDERA Software
 
PDF
Idera live 2021: Managing Digital Transformation on a Budget by Bert Scalzo
IDERA Software
 
PDF
Idera live 2021: Keynote Presentation The Future of Data is The Data Cloud b...
IDERA Software
 
PDF
Idera live 2021: Managing Databases in the Cloud - the First Step, a Succes...
IDERA Software
 
PDF
Idera live 2021: Database Auditing - on-Premises and in the Cloud by Craig M...
IDERA Software
 
PDF
Idera live 2021: Performance Tuning Azure SQL Database by Monica Rathbun
IDERA Software
 
PPTX
Geek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERA
IDERA Software
 
PPTX
How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...
IDERA Software
 
PPTX
Benefits of Third Party Tools for MySQL | IDERA
IDERA Software
 
PPTX
Achieve More with Less Resources | IDERA
IDERA Software
 
PPTX
Benefits of SQL Server 2017 and 2019 | IDERA
IDERA Software
 
The role of the database administrator (DBA) in 2020: Changes, challenges, an...
IDERA Software
 
Problems and solutions for migrating databases to the cloud
IDERA Software
 
Public cloud uses and limitations
IDERA Software
 
Optimize the performance, cost, and value of databases.pptx
IDERA Software
 
Monitor cloud database with SQL Diagnostic Manager for SQL Server
IDERA Software
 
Database administrators (dbas) face increasing pressure to monitor databases
IDERA Software
 
Six tips for cutting sql server licensing costs
IDERA Software
 
Idera live 2021: The Power of Abstraction by Steve Hoberman
IDERA Software
 
Idera live 2021: Why Data Lakes are Critical for AI, ML, and IoT By Brian Flug
IDERA Software
 
Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...
IDERA Software
 
Idera live 2021: Managing Digital Transformation on a Budget by Bert Scalzo
IDERA Software
 
Idera live 2021: Keynote Presentation The Future of Data is The Data Cloud b...
IDERA Software
 
Idera live 2021: Managing Databases in the Cloud - the First Step, a Succes...
IDERA Software
 
Idera live 2021: Database Auditing - on-Premises and in the Cloud by Craig M...
IDERA Software
 
Idera live 2021: Performance Tuning Azure SQL Database by Monica Rathbun
IDERA Software
 
Geek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERA
IDERA Software
 
How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...
IDERA Software
 
Benefits of Third Party Tools for MySQL | IDERA
IDERA Software
 
Achieve More with Less Resources | IDERA
IDERA Software
 
Benefits of SQL Server 2017 and 2019 | IDERA
IDERA Software
 
Ad

Recently uploaded (20)

PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Biography of Daniel Podor.pdf
Daniel Podor
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
July Patch Tuesday
Ivanti
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 

Geek Sync | Intro to Query Store

  • 1. Intro to Query Store By Tracy Boggiano
  • 2. Tracy Boggiano SQL Server DBA for 20+ years @TracyBoggiano databasesuperhero.com tracyboggiano speakingmentors.com
  • 3. • What It Can Do For Us? • Setup • How It Works • Reports • Usage Scenarios • 2017 Features • Troubleshooting • Best Practices Agenda
  • 4. WHAT IT CAN DO FOR US?
  • 5. What Query Store Can Do For Us? • Regressed Queries • Identify Top Consuming Queries • Audit the history of query plans • Identify Resource Consumption Patterns
  • 6. What Query Store Can Do For Us? • In 2017 • Wait Stats • Automatic plan correction • Show more statistics • In 2019 • Show even more statistics
  • 8. Query Store Setup • Run one simple command: • ALTER DATABASE [DatabaseName] SET QUERY_STORE = ON;
  • 9. Query Store Options 2016+ • Operation Mode • Data Flush Interval (Minutes) • Statistics Collection Interval • Max Size (MB) • Query Store Capture Mode • Size Based Cleanup Mode • Stale Query Threshold (Days)
  • 10. Query Store Options 2017 • Waits Statistics Capture • Max Plans Per Query
  • 11. Query Store Options 2019 • Query Store Capture Mode = CUSTOM  Stale Capture Policy Threshold  Execution Count  Total Compile CPU Time MS  Total Execution CPU Time MS
  • 12. Query Store Setup • PRIMARY filegroup • https://feedback.azure.com/forums/90803 5-sql-server/suggestions/32902072- option-to-store-query-store-data-in-a- filegroup-ot
  • 13. Query Store Setup • Per Database • Nice to have Central Repository • https://feedback.azure.com/forums/9 08035-sql- server/suggestions/33815995-create- central-repository-for-query-store
  • 14. Query Store Trace Flags • 7745 - Forces Query Store to not flush data to disk on database shutdown. • 7752 - Enables asynchronous loading of database
  • 15. GUI • Right click the database, the click on properties, then Query Store
  • 17. Query Store Setup Summary • Set your options especially size • PRIMARY filegroup • Per database • Use CUSTOM if you have ad-hoc quereies and are on 2019
  • 19. How Query Store Collects Information • Query processed by Algebrizer and sends it to the Query Optimizer • Checks for forced plan or out pops a new Execution Plan • Query Plan is put into Plan Cache • Async collects data into Query Store Memory • Async writes to disk
  • 20. Where Query Store Collects Information • Plan Store – query plan, query text, last execution time, compile time • Runtime Stats Store – all runtime stats for plans, cpu, logical reads, logical writes, physical reads, memory, tempdb, duration, execution count • Wait Stats Store – wait categories per plan
  • 22. Ways to Stabilize Perfomance • Change code and/or schema • Add RECOMPILE • Manually get the best plan in the cache • Use a plan guide • Force a plan using query store
  • 23. Regressed Queries • Identify queries that have degraded in performance • See if there is plan that can be forced easily • Force the previous plan from the history
  • 26. Check Status of Forced Queries • Query = is_forced_plan = 1 • Look at report in SSMS • Extended event
  • 28. Top Consuming Resources • Look at forcing a plan because of regression • Missing indexes • Make sure that the statistics are up-to-date • Make sure that indexes used by the query are defragmented • Consider rewriting expensive query
  • 29. Queries with High Variation
  • 34. Forcing Query Plans Manually • Using reports you can easily find queries with multiple plans and force a plan • They are not schema-bound • Should monitor for failures with Extended Events • When manually forced the plan is used even when it is no longer optimal
  • 35. A/B Testing • Rolling out new application version • Adding new hardware to the server • Creating missing indexes for expensive queries
  • 37. Summary of Usage Scenarios • Forcing Query Plans Manually • A/B testing • Upgrade SQL Server
  • 39. Wait Stats • New DMV sys.query_store_wait_stats • 23 categories • Tracks by category of wait stats such as CPU or MEMORY
  • 40. Automatic Plan Correction • Recommendations surfaced via sys.dm_db_tuning_recommendations • Can automatically switch to last known good plan • Data is in DMV even if you don’t have the option turned on • Data is lost on reboot of SQL Server
  • 41. Automatic Plan Correction Setup ALTER DATABASE CURRENT SET AUTOMATIC_TUNING (FORCE_LAST_GOOD_PLAN = ON);
  • 42. Monitoring Automatic Plan Correction • Create an Extended Events session that captures automatic tuning events • automatic_tuning_error • automatic_tuning_plan_regression_detec tion_check_completed • automatic_tuning_plan_regression_verif ication_check_completed • automatic_tuning_recommendation_expire d
  • 43. Summary of 2017 Features • Automatic Plan Correction • Wait Stats
  • 46. Perfmon Counters • Query Store CPU usage • Query Store logical reads • Query Store logical writes • Query Store physical reads
  • 48. Wait Stats • Ton of these, they all start with qds • Three can be safely ignored: • qds_async_queue • qds_cleanup_stale_queries_task_main_loop_sleep • qds_shutdown_queue • Use Paul Randal’s script is the best way to look at wait stats
  • 49. Extended Events • Over 50 events added • Most can only be used by special trace flags for Microsoft troubleshooting • We will look at script for the important ones
  • 51. Best Practices • Manage the size • Set you Statistics Interval • Make sure it is continuing to collect data • Avoid using non-parameterized queries • Avoid using drop/create process • Avoid renaming databases
  • 52. Using the Query Store with In-Memory OLTP • Turn on runtime statistics collection with sys.sp_xtp_control_query_exec_stats • Need to reset on server restart or if you clear Query Store • Memory grants metrics are not kept
  • 53. Things of Note • Forced plans can fail • Drop an index • Change the name of an index • Remove columns from an index • Forced plans for do work on the secondaries of your AGs • Forced plans don’t age out of Query Store
  • 54. Resources • Monitoring Performance By Using the Query Store - https://docs.microsoft.com/en- us/sql/relational-databases/performance/monitoring-performance-by-using-the-query- store • Best Practice with the Query Store - https://msdn.microsoft.com/en- us/library/mt604821.aspx • Wait Stats - https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog- views/sys-query-store-wait-stats-transact-sql • Automatic plan correction in SQL Server 2017 - https://blogs.msdn.microsoft.com/sqlserverstorageengine/2017/05/17/automatic-plan- correction-in-sql-server-2017/ • T-SQL Tuesday #124 Summary - https://tracyboggiano.com/archive/2020/03/t-sql- tuesday-124-query-store-summary/ • Erin Stellato’s Blog - https://www.sqlskills.com/blogs/erin/category/query-store/ • Grant Fritchey’s Blog - https://www.scarydba.com/?s=query+store