Skip to content

Commit 56070ae

Browse files
committed
edit updates
1 parent 86bab8c commit 56070ae

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

support/sql/database-engine/performance/troubleshoot-never-ending-query.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ Common causes of long-running (never-ending) queries include:
3131
- **Complex queries that have many joins and large tables:** Queries that involve many joined tables would typically have complex query plans that might take a long time to run. This scenario is common in analytical queries that don't filter out rows and that involve a large number of tables.
3232
- **Missing indexes:** Queries can be accelerated if appropriate indexes are used on tables. Indexes enable the selection of a subset of the data to provide faster access.
3333

34-
## Resolution
34+
## Solution
3535

36-
### Step 1. Discover never-ending queries
36+
### Step 1: Discover never-ending queries
3737

3838
Look for a never-ending query that's running on the system. You have to determine whether a query has a long execution time, a long wait time (stuck on a bottleneck), or a long compilation time.
3939

40-
#### 1.1 Run a diagnostic
40+
#### 1.1 Run a diagnostic
4141

4242
Run the following diagnostic query on your SQL Server instance where the never-ending query is active:
4343

@@ -92,7 +92,7 @@ END
9292

9393
There are several scenarios that can cause a query to run for a long time: long execution, long wait, and long compilation. For more information about why a query might run slowly, see [Running vs. Waiting: why are queries slow?](troubleshoot-slow-running-queries.md#running-vs-waiting-why-are-queries-slow)
9494

95-
#### Long execution time
95+
##### Long execution time
9696

9797
The troubleshooting steps in this article are applicable when you receive an output similar to the following, where the CPU time is increasing proportionately to the elapsed time without significant wait times.
9898

@@ -114,7 +114,7 @@ In this situation, the query is reading rows, joining, processing results, calcu
114114
115115
If the slow query meets these criteria, focus on reducing its runtime. Typically, reducing runtime involves reducing the number of rows that the query has to process throughout its life by applying indexes, rewriting the query, or updating statistics. For more information, see the [Resolution](#step-4-resolution) section.
116116

117-
#### Long wait time
117+
##### Long wait time
118118

119119
This article isn't applicable for long wait scenarios. In a wait scenario, you might receive an output that resembles the following example in which the CPU usage doesn't change or changes slightly because the session is waiting on a resource:
120120

@@ -124,15 +124,11 @@ This article isn't applicable for long wait scenarios. In a wait scenario, you m
124124

125125
The wait type indicates that the session is waiting on a resource. A long elapsed time and a long wait time indicate that the session is waiting for most its life for this resource. Тhe short CPU time indicates that little time was spent actually processing the query.
126126

127-
To troubleshoot queries that are long because of waits, see the following article:
128-
129-
[!INCLUDE [collect query data and logical reads](../../includes/performance/diagnose-waits-or-bottlenecks.md)]
130-
131-
#### Long compilation time
127+
##### Long compilation time
132128

133129
On rare occasions, you might observe that the CPU usage increases continuously over time but isn't driven by the query run. Instead, an excessively long compilation (the parsing and compiling of a query) might be the cause. In these cases, check the `transaction_name` output column for a value of `sqlsource_transform`. This transaction name indicates a compilation.
134130

135-
### 2. Collect diagnostic logs manually
131+
### Step 2: Collect diagnostic logs manually
136132

137133
After you determine that a never-ending query exists on the system, you can collect the query's plan data to troubleshoot further. To collect the data, use one of the following methods, depending on your version of SQL Server.
138134

@@ -349,7 +345,7 @@ You can use [SQL LogScout](https://github.com/microsoft/SQL_LogScout/releases) t
349345
350346
SQL LogScout captures at least three query plans for each high-CPU-consuming query. You can find file names that resemble `servername_datetime_NeverEnding_statistics_QueryPlansXml_Startup_sessionId_#.sqlplan`. You can use these files in the next step when you review plans to identify the reason for long query execution.
351347
352-
### Step 3. Review the collected plans
348+
### Step 3: Review the collected plans
353349
354350
This section discusses how to review the collected data. It uses the multiple XML query plans (using extension `.sqlplan`) that are collected in Microsoft SQL Server 2016 SP1 and later builds and versions.
355351
@@ -369,7 +365,7 @@ This section discusses how to review the collected data. It uses the multiple XM
369365
370366
:::image type="content" source="media/troubleshoot-never-ending-query/query-plan-comparison.png" alt-text="Screenshot that shows comparing query plans in SSMS." lightbox="media/troubleshoot-never-ending-query/query-plan-comparison.png":::
371367
372-
### Step 4. Resolution
368+
### Step 4: Resolution
373369
374370
1. Make sure that statistics are updated for the tables that are used in the query.
375371
@@ -393,3 +389,8 @@ This section discusses how to review the collected data. It uses the multiple XM
393389
- USE `PLAN N'<xml_plan>'` (if you have a fast query plan that you can force)
394390

395391
1. Use Query Store (QDS) to force a good known plan if such a plan exists and if your SQL Server version supports Query Store.
392+
393+
## Related content
394+
395+
- [Troubleshoot slow-running queries in SQL Server](/troubleshoot/sql/database-engine/performance/troubleshoot-slow-running-queries)
396+
- [Troubleshoot a query that shows a significant performance difference between two servers](/troubleshoot/sql/database-engine/performance/troubleshoot-query-perf-between-servers)

0 commit comments

Comments
 (0)