Among all of the new SQL Server 2016 Database Engine features Query Store stands out as a great addition to the performance tuning tools currently available out of the box.The Query Store feature helps you to track query plans, runtime statistics and queries/plans history. It also helps you find regressing queries. You can quickly find new queries with multiple plans, identify un-efficient plans and force a better plan.
Query Store could be enabled and configured using the new "Query Store" database property page:

It could also be enabled using T-SQL:
ALTER DATABASE [DEMO_1] |
SQL 2016 Query Store Configuration
Once you enabled the Query Store for the database you can configure other Query Store settings (configurable settings are in bold font and highlighted):

Click on each property to see it's description. You can find more details about each configuration option here.The Query Store configuration can also be changed using T-SQL:
| ALTER DATABASE [DEMO_1] SET query_store (operation_mode = read_only, cleanup_policy = ( stale_query_threshold_days = 367), data_flush_interval_seconds = 900, interval_length_minutes = 60, max_storage_size_mb = 100, query_capture_mode = auto, size_based_cleanup_mode = auto) go |
Let's review other information that is available on the "Query Store" property page.

ALTER DATABASE [DEMO_1] |
| EXEC sys.Sp_query_store_flush_db |
| SELECT NAME, type_desc FROM sys.all_objects WHERE NAME LIKE '%query_store%' OR NAME = 'query_context_settings' |

Also, there are 19 new extended events:
SQL Server Management Studio (SSMS) Query Store Features
After enabling Query Store the database will have the new "Query Store" container in SSMS:

You can right click the "Query Store" container to view available options:


Most of the Query Store panes have similar structure and display options. Let's review them on the "Top Resource Consumers" pane example:

The right chart of the pane (called "Plan Summary") displays statistics of the selected/highlighted query (green bar on the left chart) based on the selected "Metric" (1) and "Statistic" (2). Selected "Statistic" becomes a vertical axis for the right chart.
Refresh button on the left chart will refresh both charts. The same button on the right chart will only refresh the right chart.
Note that we have selected query with multiple plans for review ("num plans" vertical axis on the left chart). The right chart displays each plan in different color.
You can mouse over (3) on a left or right chart's object and see the detailed statistics for specific query_id or plan_id.The details will be different depending on the metric selected:

When you click on different plans ((3) or (4)) the bottom part of the pane (5) will display the execution plan for this particular plan_id.
Note some of the titles that are dynamic. The pane's name (6) will be "Top Resource Consumers [db_name]". The header in our example is: "Top 25 Top Resource Consumers During the last hour for database qstore_test". Where these parts of the title are dynamic:
Let's review the dropdown menus in the "Top Resource Consumers" pane:

(1) Metrics available:
(2) Left Chart - Vertical Axis:
(3) Statistics:
(4) Left Chart - Horizontal Axis:
(5) Right Chart ("Plan Summary") Vertical Axis changes based on the "Statistics" selected on the left chart:
Note, that if "Total" statistics selected on the left chart the right chart's axis is set to "Avg". This might change in the final release.
(6) If you have smaller screen resolution some buttons will be hidden.
Let's click "Grid" on the right chart and "Vertical View" next to the title and review the buttons available:

Changing the "Plan Summary" from chart to grid allows us to view statistics for every plan in table format.
The "Track Query" (1) button will open "Tracked Queries" pane. We will review this pane in our next tip.
The "View Query" (2) will open the new SSMS window with T-SQL script of the query:

The "Detailed Grid" button (3) on the left chart will display a list of the top queries with all statistics (more columns displayed):

The "Grid" button (4) on the left chart displays list of top queries, but the number of columns will be limited and the columns displayed will depend on the statistic and metric selected:


Here are "Time Interval" options:



The "Force plan" button is available under the execution plan section and on the left chart.
Years of Experience
Gratified Students
Training Batches
Training Hours
Please subscribe our technical blog to get recent updates.