How do I obtain a Query Execution Plan in SQL Server?

前端 未结 12 1894
不知归路
不知归路 2020-11-21 04:17

In Microsoft SQL Server how can I get a query execution plan for a query / stored procedure?

12条回答
  •  清酒与你
    2020-11-21 05:13

    Starting from SQL Server 2016+, Query Store feature was introduced to monitor performance. It provides insight into query plan choice and performance. It’s not a complete replacement of trace or extended events, but as it’s evolving from version to version, we might get a fully functional query store in future releases from SQL Server. The primary flow of Query Store

    1. SQL Server existing components interact with query store by utilising Query Store Manager.
    2. Query Store Manager determines which Store should be used and then passes execution to that store (Plan or Runtime Stats or Query Wait Stats)
      • Plan Store - Persisting the execution plan information
      • Runtime Stats Store - Persisting the execution statistics information
      • Query Wait Stats Store - Persisting wait statistics information.
    3. Plan, Runtime Stats and Wait store uses Query Store as an extension to SQL Server.

    1. Enabling the Query Store: Query Store works at the database level on the server.

      • Query Store is not active for new databases by default.
      • You cannot enable the query store for the master or tempdb database.
      • Available DMV

        sys.database_query_store_options (Transact-SQL)

    2. Collect Information in the Query Store: We collect all the available information from the three stores using Query Store DMV (Data Management Views).

      • Query Plan Store: Persisting the execution plan information and it is accountable for capturing all information that is related to query compilation.

        sys.query_store_query (Transact-SQL) sys.query_store_plan (Transact-SQL) sys.query_store_query_text (Transact-SQL)

      • Runtime Stats Store: Persisting the execution statistics information and it is probably the most frequently updated store. These statistics represent query execution data.

        sys.query_store_runtime_stats (Transact-SQL)

      • Query Wait Stats Store: Persisting and capturing wait statistics information.

        sys.query_store_wait_stats (Transact-SQL)

    NOTE: Query Wait Stats Store is available only in SQL Server 2017+

提交回复
热议问题