【发布时间】:2021-02-10 16:49:08
【问题描述】:
我有普通的SELECT 查询,它返回相对较大的数据集(11k 行),并且在我的应用程序运行时随机超时。这发生在我自己的使用 localdb 的开发笔记本电脑上。当它工作时,它几乎立即返回数据,其他时候 - Microsoft.Data.SqlClient.SqlException: The wait operation timed out.。当它使用 SSMS 失败时也会感觉迟钝,但它总是会完成查询。
SQL如下
(@CurrentUserId int)
-- First, select Draft issues created by current user
SELECT [I].[IssueId]
,[I].[IssueGuid]
,[I].[IssueNumber]
,[I].[DateCreated]
,[I].[DateOpened]
,[I].[DateLastModified]
,[I].[DateClosed]
,[I].[Title]
,[I].[Type]
,[I].[Status]
,[I].[CreatedByUserId]
,1 AS [OrderKey]
FROM [cm].[IssuesTbl] [I]
WHERE [I].[Status] = 0 AND [I].[CreatedByUserId] = @CurrentUserId
UNION ALL
-- Last, select Open issues
SELECT [I].[IssueId]
,[I].[IssueGuid]
,[I].[IssueNumber]
,[I].[DateCreated]
,[I].[DateOpened]
,[I].[DateLastModified]
,[I].[DateClosed]
,[I].[Title]
,[I].[Type]
,[I].[Status]
,[I].[CreatedByUserId]
,2 AS [OrderKey]
FROM [cm].[IssuesTbl] [I]
WHERE [I].[Status] = 1
ORDER BY [OrderKey] ASC, [I].[DateOpened] DESC, [I].[DateCreated] DESC
执行计划是here.
我安装了 Blitz 并运行 sp_BlitzFirst 给我一些想法,但我不确定要查找什么以及如何解决问题。请帮忙。
@@version:
Microsoft SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64) Oct 28 2016 18:17:30 Copyright (c) Microsoft Corporation Express Edition (64-bit) on Windows 10 Enterprise 6.3 <X64> (Build 17134: )
sp_BlitzFirst:
10 Server Performance Poison Wait Detected: RESOURCE_SEMAPHORE
For 4 seconds over the last 5 seconds, SQL Server was waiting on this particular bottleneck.
200 Wait Stats RESOURCE_SEMAPHORE
For 4 seconds over the last 5 seconds, SQL Server was waiting on this particular bottleneck.
【问题讨论】:
-
请添加查询或查询计划。
标签: sql sql-server timeout query-performance