SQLServer 索引引起大量超时和死锁!
发布时间:2020-12-12 13:10:50 所属栏目:MsSql教程 来源:网络整理
导读:今天出现了大量的死锁和超时,确定是某个用户使用,用户并发几百个账号操作(属正常情况,一个用户可以有多个账号)。但是数据库跟踪到大量死锁和超时的语句。超时的语句单独执行时也挺快,估计是死锁太多也导致了其他查询超时。该用户之前还正常,不知道今
今天出现了大量的死锁和超时,确定是某个用户使用,用户并发几百个账号操作(属正常情况,一个用户可以有多个账号)。但是数据库跟踪到大量死锁和超时的语句。超时的语句单独执行时也挺快,估计是死锁太多也导致了其他查询超时。该用户之前还正常,不知道今天是不是有类似开业的的情形,今天出现很多死锁超时。当然我们是按用户数据操作的,对其他的用户影响是较小的!~ 其死锁语句类型如下(有做更改了别名) deadlock-list deadlock victim=process2c1996748 process-list process id=process2c1996748 taskpriority=0 logused=0 waitresource=KEY: 5:72057595783413760 (27043abd31be) waittime=2408 ownerId=5280849304 transactionname=user_transaction lasttranstarted=2015-11-25T15:18:55.770 XDES=0x4beab03b0 lockMode=S schedulerid=4 kpid=4964 status=suspended spid=775 sbid=0 ecid=0 priority=0 trancount=1 lastbatchstarted=2015-11-25T15:18:56.487 lastbatchcompleted=2015-11-25T15:18:56.460 lastattention=2015-11-25T15:16:17.937 clientapp=.Net SqlClient Data Provider hostname=Domain-PLAT08 hostpid=1816 loginname=DomainLoginUser isolationlevel=repeatable read (3) xactid=5280849304 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056 executionStack frame procname=adhoc line=1 stmtstart=124 sqlhandle=0x0200000019c2ae1ebeae5b9efaa67c53bf3ca1da7d367b59 SELECT TOP (1) [t0].[id],[t0].[Storeid],[t0].[GoodsItemid],[t0].[BatchNumber],[t0].[BillNumber],[t0].[Balance],[t0].[Type],[t0].[Number],[t0].[LoginUser],[t0].[OperateTime],[t0].[SubmitTime],[t0].[Meno] FROM [dbo].[VTableAA] AS [t0] WHERE ([t0].[Storeid] = @p0) AND ([t0].[GoodsItemid] = @p1) AND (([t0].[BatchNumber] IS NULL) OR ([t0].[BatchNumber] = @p2)) ORDER BY [t0].[OperateTime] DESC frame procname=unknown line=1 sqlhandle=0x000000000000000000000000000000000000000000000000 unknown inputbuf (@p0 uniqueidentifier,@p1 uniqueidentifier,@p2 nvarchar(4000)) SELECT TOP (1) [t0].[id],[t0].[Meno] FROM [dbo].[VTableAA] AS [t0] WHERE ([t0].[Storeid] = @p0) AND ([t0].[GoodsItemid] = @p1) AND (([t0].[BatchNumber] IS NULL) OR ([t0].[BatchNumber] = @p2)) ORDER BY [t0].[OperateTime] DESC process id=process88f10db88 taskpriority=0 logused=14620 waitresource=HOBT: 5:72057595845410816 waittime=4008 ownerId=5280847097 transactionname=user_transaction lasttranstarted=2015-11-25T15:18:54.157 XDES=0x110494ea0 lockMode=IX schedulerid=2 kpid=9420 status=suspended spid=1253 sbid=0 ecid=0 priority=0 trancount=2 lastbatchstarted=2015-11-25T15:18:55.017 lastbatchcompleted=2015-11-25T15:18:55.013 clientapp=.Net SqlClient Data Provider hostname=Domain-PLAT07 hostpid=4588 loginname=DomainLoginUser isolationlevel=repeatable read (3) xactid=5280847097 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056 executionStack frame procname=adhoc line=2 stmtstart=556 stmtend=1200 sqlhandle=0x020000003b685607e5ff166e70acd8287bbbe3b5d7897bdd INSERT INTO [dbo].[VTableBB]([Userid],[Type],[Way],[Value],[Money],[LastValue],[Balance],[BillNumber],[LoginUser],[Storeid],[OperateTime],[Meno],[Sourceid],[IsUndo]) OUTPUT INSERTED.[id] INTO @output VALUES (@p0,@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9,@p10,@p11,@p12,@p13) frame procname=unknown line=1 sqlhandle=0x000000000000000000000000000000000000000000000000 unknown inputbuf (@p0 uniqueidentifier,@p1 int,@p2 int,@p3 decimal(5,4),@p4 decimal(5,@p5 decimal(1,0),@p6 decimal(8,@p7 nvarchar(4000),@p8 nvarchar(4000),@p9 uniqueidentifier,@p10 datetime,@p11 nvarchar(4000),@p12 uniqueidentifier,@p13 bit) DECLARE @output TABLE([id] UniqueIdentifier) INSERT INTO [dbo].[VTableBB]([Userid],@p13) SELECT [id] FROM @output resource-list keylock hobtid=72057595783413760 dbid=5 objectname=MyDB.dbo.TableAA indexname=PK_TableAA id=lock4fdcdd000 mode=X associatedObjectId=72057595783413760 owner-list owner id=process88f10db88 mode=X waiter-list waiter id=process2c1996748 mode=S requestType=wait hobtlock hobtid=72057595845410816 subresource=FULL dbid=5 objectname=MyDB.dbo.TableBB indexname=IX_TableBB_UID_OperateTime id=lockdd0cdd180 mode=S associatedObjectId=72057595845410816 owner-list owner id=process2c1996748 mode=S waiter-list waiter id=process88f10db88 mode=IX requestType=convert 开始想是程序中有交叉的事务,但是查找确实麻烦,而且我们程序处理过程确实繁琐。开始考虑是索引问题,我们是进行表分区的,设置分区内部的锁升级可升级到分区锁。问题就出现在该信息中: hobtlock hobtid=72057595845410816 subresource=FULL dbid=5 objectname=MyDB.dbo.TableBB indexname=IX_TableBB_UID_OperateTime 用户每秒钟对表?TableBB 有大量插入和查询,死锁信息中,插入表数据时,使用了分区锁 (hobtlock hobtid=72057595845410816 subresource=FULL)。而引起死锁的不是聚集索引,是非聚集索引?IX_TableBB_UID_OperateTime 导致的。即插入数据时,除了聚集索引需要排序,非聚集索引同样也要排序,当整个分区中该表的非聚集索引被占用时,其他事务就需要等待了,甚至出现死锁!~所以猜测是表?TableBB 的索引?IX_TableBB_UID_OperateTime 引起的。 最终解决方法:删除索引解决! DROP INDEX IX_TableBB_UID_OperateTime ON dbo.TableBB; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |