- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我真的很感激这方面的帮助。这让我难住了。基本上,我在事务中运行带有一系列 Delete 语句的 Proc。此过程将由多线程应用程序调用,因此调用次数很多。大多数语句都执行得很好,但最后一个语句因 Key lock 问题而陷入僵局。好像跟Primary Key和它上面的聚簇索引PK_Payloads有关。我附上了所有相关信息。感谢您提供的任何帮助。
DDL
CREATE TABLE [dbo].[Payloads]
(
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Guid] [uniqueidentifier] NOT NULL DEFAULT NEWID(),
[Name] [nvarchar](max) NOT NULL,
[LastProcessedDate] [datetime] NOT NULL DEFAULT GETDATE(),
[SourceSystem] [nvarchar](32) NOT NULL,
[DestinationSystem] [nvarchar](32) NULL,
[Error] [bit] NOT NULL DEFAULT 0,
[ErrorDetails] [nvarchar](max) NULL,
[CreateDate] [datetime] NOT NULL DEFAULT GETDATE(),
[TypeId] [tinyint] NOT NULL,
[StatusId] [smallint] NOT NULL,
[TagId] [integer] NULL,
[EngineExecutionCrawlLocationId] [bigint] NOT NULL,
[PayloadId] [bigint] NULL,
CONSTRAINT [PK_Payloads] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Payloads_W] FOREIGN KEY([TypeId]) REFERENCES [dbo].[W] ([Id]),
CONSTRAINT [FK_Payloads_X] FOREIGN KEY([StatusId]) REFERENCES [dbo].[X] ([Id]),
CONSTRAINT [FK_Payloads_Y] FOREIGN KEY([TagId]) REFERENCES [dbo].[Y] ([Id]),
CONSTRAINT [FK_Payloads_Z] FOREIGN KEY([EngineExecutionCrawlLocationId]) REFERENCES [dbo].[Z] ([Id]),
CONSTRAINT [FK_Payloads_Payloads] FOREIGN KEY([PayloadId]) REFERENCES [dbo].[Payloads] ([Id])
)
外键上也有非聚集索引,也有几个覆盖非聚集索引。
CREATE NONCLUSTERED INDEX [Payloads_I5] ON [dbo].[Payloads]
(
[Id] ASC
)
INCLUDE ([Name], [StatusId]) WITH (SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]
过程
DECLARE @Details NVARCHAR(MAX)
SELECT @Details = 'Name: ' + p.[Name] + ', Source Ref: ' + pc.[SourceContentReference]
+ ', Quarantine Ref: ' + ISNULL(pc.[DestinationContentReference], '')
+ ', Archive Ref: ' + ISNULL(pc.[ArchiveContentReference], '')
FROM Payloads p
INNER JOIN PayloadContent pc ON p.[Id] = pc.[PayloadId]
WHERE p.[Id] = @PayloadId
BEGIN TRANSACTION
-- Audit Payload Deleted
INSERT INTO [Audit] ([AuditTypeId], [ObjectId], [Details])
VALUES (1, @PayloadId, ISNULL(@Details, ''))
DELETE FROM [A]
WHERE [PayloadId] = @PayloadId
DELETE FROM
WHERE [PayloadId] = @PayloadId
DELETE FROM [C]
WHERE [PayloadId] = @PayloadId
DELETE FROM [D]
WHERE [PayloadId] = @PayloadId
DELETE FROM [E]
WHERE [PayloadId] = @PayloadId
DELETE FROM [F]
WHERE [PayloadContentId] IN (SELECT [Id]
FROM [G]
WHERE [PayloadId] = @PayloadId)
DELETE FROM [G]
WHERE [PayloadId] = @PayloadId
/* Offending statement Here */
DELETE FROM [Payloads]
WHERE [Id] = @PayloadId
COMMIT TRANSACTION
死锁图
<deadlock victim="process940c6088">
<process-list>
<process id="process940c6088" taskpriority="0" logused="3080" waitresource="KEY: 31:72057594041139200 (5cd3004a5da8)" waittime="2431" ownerId="85480" transactionname="user_transaction" lasttranstarted="2012-07-26T11:24:03.970" XDES="0x98861950" lockMode="S" schedulerid="4" kpid="5432" status="suspended" spid="58" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2012-07-26T11:24:03.970" lastbatchcompleted="2012-07-26T11:24:03.923" clientapp=".Net SqlClient Data Provider" hostname="CRUSADER" hostpid="2792" loginname="AIL\matt" isolationlevel="read committed (2)" xactid="85480" currentdb="31" lockTimeout="4294967295" clientoption1="673185824" clientoption2="128056">
<executionStack>
<frame procname="AI.DataPoint.Database.dbo.DeletePayload" line="47" stmtstart="2474" stmtend="2580" sqlhandle="0x03001f00fb1c2229b2c7b7009aa000000100000000000000">
DELETE FROM [Payloads]
WHERE [Id] = @PayloadId </frame>
</executionStack>
<inputbuf>
Proc [Database Id = 31 Object Id = 690101499] </inputbuf>
</process>
<process id="process4dd048" taskpriority="0" logused="3732" waitresource="KEY: 31:72057594041139200 (a903f5656cf9)" waittime="2413" ownerId="85496" transactionname="user_transaction" lasttranstarted="2012-07-26T11:24:03.987" XDES="0x9724e3b0" lockMode="S" schedulerid="4" kpid="2560" status="suspended" spid="60" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2012-07-26T11:24:03.987" lastbatchcompleted="2012-07-26T11:24:03.940" clientapp=".Net SqlClient Data Provider" hostname="CRUSADER" hostpid="2792" loginname="AIL\matt" isolationlevel="read committed (2)" xactid="85496" currentdb="31" lockTimeout="4294967295" clientoption1="673185824" clientoption2="128056">
<executionStack>
<frame procname="AI.DataPoint.Database.dbo.DeletePayload" line="47" stmtstart="2474" stmtend="2580" sqlhandle="0x03001f00fb1c2229b2c7b7009aa000000100000000000000">
DELETE FROM [Payloads]
WHERE [Id] = @PayloadId </frame>
</executionStack>
<inputbuf>
Proc [Database Id = 31 Object Id = 690101499] </inputbuf>
</process>
<process id="process4c3b88" taskpriority="0" logused="3732" waitresource="KEY: 31:72057594041139200 (b6d1e11077fc)" waittime="2288" ownerId="85471" transactionname="user_transaction" lasttranstarted="2012-07-26T11:24:03.930" XDES="0x83925950" lockMode="S" schedulerid="3" kpid="5608" status="suspended" spid="56" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2012-07-26T11:24:03.927" lastbatchcompleted="2012-07-26T11:24:03.927" clientapp=".Net SqlClient Data Provider" hostname="CRUSADER" hostpid="2792" loginname="AIL\matt" isolationlevel="read committed (2)" xactid="85471" currentdb="31" lockTimeout="4294967295" clientoption1="673185824" clientoption2="128056">
<executionStack>
<frame procname="AI.DataPoint.Database.dbo.DeletePayload" line="47" stmtstart="2474" stmtend="2580" sqlhandle="0x03001f00fb1c2229b2c7b7009aa000000100000000000000">
DELETE FROM [Payloads]
WHERE [Id] = @PayloadId </frame>
</executionStack>
<inputbuf>
Proc [Database Id = 31 Object Id = 690101499] </inputbuf>
</process>
<process id="process4dd288" taskpriority="0" logused="3732" waitresource="KEY: 31:72057594041139200 (a903f5656cf9)" waittime="2427" ownerId="85487" transactionname="user_transaction" lasttranstarted="2012-07-26T11:24:03.973" XDES="0x800bf950" lockMode="S" schedulerid="4" kpid="2900" status="suspended" spid="59" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2012-07-26T11:24:03.973" lastbatchcompleted="2012-07-26T11:24:03.933" clientapp=".Net SqlClient Data Provider" hostname="CRUSADER" hostpid="2792" loginname="AIL\matt" isolationlevel="read committed (2)" xactid="85487" currentdb="31" lockTimeout="4294967295" clientoption1="673185824" clientoption2="128056">
<executionStack>
<frame procname="AI.DataPoint.Database.dbo.DeletePayload" line="47" stmtstart="2474" stmtend="2580" sqlhandle="0x03001f00fb1c2229b2c7b7009aa000000100000000000000">
DELETE FROM [Payloads]
WHERE [Id] = @PayloadId </frame>
</executionStack>
<inputbuf>
Proc [Database Id = 31 Object Id = 690101499] </inputbuf>
</process>
</process-list>
<resource-list>
<keylock hobtid="72057594041139200" dbid="31" objectname="AI.DataPoint.Database.dbo.Payloads" indexname="PK_Payloads" id="lock97039400" mode="X" associatedObjectId="72057594041139200">
<owner-list>
<owner id="process4c3b88" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="process940c6088" mode="S" requestType="wait"/>
</waiter-list>
</keylock>
<keylock hobtid="72057594041139200" dbid="31" objectname="AI.DataPoint.Database.dbo.Payloads" indexname="PK_Payloads" id="lock8a589900" mode="X" associatedObjectId="72057594041139200">
<owner-list/>
<waiter-list>
<waiter id="process4dd048" mode="S" requestType="wait"/>
</waiter-list>
</keylock>
<keylock hobtid="72057594041139200" dbid="31" objectname="AI.DataPoint.Database.dbo.Payloads" indexname="PK_Payloads" id="lock8a589000" mode="X" associatedObjectId="72057594041139200">
<owner-list>
<owner id="process4dd048" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="process4c3b88" mode="S" requestType="wait"/>
</waiter-list>
</keylock>
<keylock hobtid="72057594041139200" dbid="31" objectname="AI.DataPoint.Database.dbo.Payloads" indexname="PK_Payloads" id="lock8a589900" mode="X" associatedObjectId="72057594041139200">
<owner-list>
<owner id="process940c6088" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="process4dd288" mode="S" requestType="wait"/>
</waiter-list>
</keylock>
</resource-list>
</deadlock>
最佳答案
您需要一个关于Payloads(PayloadID)
的索引。没有它,FK 验证必须进行表扫描。这也将帮助所有其他 DELETE,但其他 DELETE 也一样,它们非常低效。其他删除不会死锁,因为它们是表扫描,因此都按相同的顺序进行。最后一个至少可以从 [Id]
上的索引中受益,但这样做会导致与所有这些扫描的顺序冲突。
关于sql-server - 尝试同时运行 Delete 语句时,KEY Lock 上的 SQL Server 死锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11670452/
我写了这个课: class StaticList { private: int headFree; int headList; int locNe
我目前正在使用 SQL Server Management Studio 2005,我遇到了一些问题,但首先是我的 DB 架构的摘录(重要的): imghack link to the image 我
范围:两个表。创建新顾客时,他们会将一些有关他们的信息存储到第二个表中(这也是使用触发器完成的,它按预期工作)。这是我的表结构和关系的示例。 表 1-> 赞助人 +-----+---------+--
我想知道,在整个程序中,我使用了很多指向 cstrings 的 char* 指针,以及其他指针。我想确保在程序完成后删除所有指针,即使 Visual Studio 和 Code Blocks 都为我做
考虑以下代码: class Foo { Monster* monsters[6]; Foo() { for (int i = 0; i < 6; i++)
关于 this page , 是这么写的 One reason is that the operand of delete need not be an lvalue. Consider: delet
我无法在 DELETE CASCADE ON UPDATE CASCADE 上添加外键约束。 我使用两个简单的表格。 TAB1 有 2 列:ID int(10) unsigned NOT NULL A
你好,有没有办法把它放在一个声明中? DELETE e_worklist where wbs_element = '00000000000000000054TTO'. DELETE e_workli
我有一个表,它是我系统的核心,向我的客户显示的所有结果都存储在那里。它增长得非常快,因此每 3 小时我应该删除早于 X 的记录以提高性能。 仅删除这些记录就足够了,还是应该在删除后运行优化表? 我正在
这个问题在这里已经有了答案: delete vs delete[] operators in C++ (7 个答案) 关闭 9 年前。 做和做有什么区别: int* I = new int[100]
为什么这段代码是错误的?我是否遗漏了有关 delete 和 delete[] 行为的内容? void remove_stopwords(char** strings, int* length) {
当我使用 new [] 申请内存时。最后,我使用 delete 来释放内存(不是 delete[])。会不会造成内存泄漏? 两种类型: 内置类型,如 int、char、double ... 我不确定。
所以在代码审查期间,我的一位同事使用了 double* d = new double[foo]; 然后调用了 delete d。我告诉他们应该将其更改为 delete [] d。他们说编译器不需要基本
范围:两个表。当一个新顾客被创建时,他们将一些关于他们的信息存储到第二个表中(这也是使用触发器完成的,它按预期工作)。这是我的表结构和关系的示例。 表 1-> 赞助人 +-----+---------
C++14 介绍 "sized" versions of operator delete ,即 void operator delete( void* ptr, std::size_t sz ); 和
我正在执行类似的语句 DELETE FROM USER WHERE USER_ID=1; 在 SQLDeveloper 中。 由于用户在许多表中被引用(例如用户有订单、设置等),我们激活了 ON DE
出于某种原因,我找不到我需要的确切答案。我在这里搜索了最后 20 分钟。 我知道这很简单。很简单。但由于某种原因我无法触发触发器.. 我有一个包含两列的表格 dbo.HashTags |__Id_|_
这是我的代码: #include #include #include int main() { setvbuf(stdout, NULL, _IONBF, 0); setvbuf
是否可以在 postgres 中使用单个命令删除所有表中的所有行(不破坏数据库),或者在 postgres 中级联删除? 如果没有,那么我该如何重置我的测试数据库? 最佳答案 is it possib
我想删除一些临时文件的内容,所以我正在开发一个小程序来帮我删除它们。我有这两个代码示例,但我对以下内容感到困惑: 哪个代码示例更好? 第一个示例 code1 删除文件 1 和 2,但第二个示例 cod
我是一名优秀的程序员,十分优秀!