Butuh Bantuan Pemecahan Masalah Sql Server 2005 Skenario Kebuntuan


9

Saya mengalami skenario kebuntuan di mana satu-satunya peserta dalam kebuntuan tampaknya menjadi satu tabel dan satu prosedur tersimpan yang menghapus dari tabel itu. Saya menarik kesimpulan itu berdasarkan analisis saya tentang log galat sql pada saat beberapa dari kebuntuan ini, menggunakan artikel MSDN di bawah ini sebagai pedoman untuk menguraikan jejak di log kesalahan.

Tabel DEXTable dan prosedur tersimpan ClearDEXTableRows didefinisikan di bawah ini. Ada prosedur tersimpan lainnya, InsertDEXTableRow yang menyisipkan baris ke DEXTable, tetapi proc tersebut tampaknya tidak terlibat dalam kebuntuan berdasarkan entri dalam log galat sql.

DEXTable memiliki ~ 8,3 juta baris di dalamnya, dan cenderung tumbuh dengan mantap. Tabel Responden juga besar dan cenderung tumbuh dengan mantap.

Itu diakses dari situs web volume lalu lintas tinggi dengan halaman yang sering memanggil ClearDEXTableRows dan InsertDEXTableRow berturut-turut cepat.

Kebuntuan telah terjadi antara 0 dan 9 kali per hari selama 10 hari terakhir.

Saya telah mengaktifkan jejak sql untuk 1222 (menggunakan DBCC TRACEON 1222) dan baru-baru ini mengaktifkan flag 1204. Ada deskripsi yang bagus tentang output untuk flag-flag ini pada Mendeteksi dan Mengakhiri Deadlock

Pertanyaan saya adalah:

Apakah masuk akal bahwa hanya prosedur yang tersimpan ini ClearDEXTableRows yang menjadi penyebab kebuntuan?

Jika demikian , adakah yang bisa memberikan penjelasan yang baik tentang bagaimana ini bisa terjadi dan merekomendasikan cara untuk memperbaikinya?
Kecurigaan saya adalah bahwa pernyataan DELETE menyebabkan perselisihan pada PK untuk DEXTable yang perlu sering dibangun kembali.

Jika tidak , jejak tambahan apa yang harus saya aktifkan untuk menggali lebih dalam penyebab kebuntuan? (Saya ingin belajar di sini)

-- Table definition
CREATE TABLE [dbo].[DEXTable](
                [ExportID] [int] NOT NULL,
                [RespondentID] [int] NOT NULL,
                [Exported] [datetime] NOT NULL,
CONSTRAINT [PK_DEXTable] PRIMARY KEY CLUSTERED
(
                [ExportID] ASC,
                [RespondentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[DEXTable]  WITH CHECK ADD  CONSTRAINT [FK_DEXTable_Exports] FOREIGN KEY([ExportID])
REFERENCES [dbo].[Exports] ([ExportID])
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[DEXTable] CHECK CONSTRAINT [FK_DEXTable_Exports]
GO

ALTER TABLE [dbo].[DEXTable]  WITH CHECK ADD  CONSTRAINT [FK_DEXTable_Respondents] FOREIGN KEY([RespondentID])
REFERENCES [dbo].[Respondents] ([RespondentID])
GO

ALTER TABLE [dbo].[DEXTable] CHECK CONSTRAINT [FK_DEXTable_Respondents]
GO

ALTER TABLE [dbo].[DEXTable] ADD  DEFAULT (getdate()) FOR [Exported]
GO

-- "ClearDEXTableRows"
-- Clear a respondent's export records to trigger re-export.
CREATE PROCEDURE [dbo].[ClearDEXTableRows]
    @RespondentID int
AS
    DELETE DEXTable WITH (ROWLOCK)
    WHERE RespondentID = @RespondentID
GO

-- "InsertDEXTableRow"
-- Insert record noting export run for a particular respondent.
CREATE PROCEDURE [dbo].[InsertDEXTableRow]
    @ExportID int,
    @RespondentID int
AS
    IF NOT EXISTS (SELECT RespondentID FROM DEXTable WHERE ExportID = @ExportID AND RespondentID = @RespondentID)
    BEGIN
      INSERT DEXTable
        (ExportID, RespondentID, Exported)
      VALUES
        (@ExportID, @RespondentID, getdate())
    END
    ELSE
    BEGIN
      UPDATE DEXTable
      SET Exported = getdate()
      WHERE ExportID = @ExportID AND RespondentID = @RespondentID
    END
GO

Dan berikut adalah beberapa entri log (Saya tidak sepenuhnya yakin apa yang membantu)

-- Sql error log for one of the recent deadlocks
-- Most recent entries in the log are at the top and go further back in time as you read down

11/17/2011 00:00:58,spid18s,Unknown,This instance of SQL Server has been using a process ID of 1840 since 10/31/2011 7:19:43 PM (local) 11/1/2011 12:19:43 AM (UTC). This is an informational message only; no user action is required.

11/16/2011 20:37:59,spid20s,Unknown,waiter id=process86a6478 mode=U requestType=wait

11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processac352e9b8 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lockd32579f80 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter id=process47eda8 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processac352e9b8 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lockc48e52780 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter id=processce50ce088 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processac352e9b8 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=locka6ad4e580 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter id=process8691198 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processcd7b1b048 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lock95f600780 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter id=process478da8 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processcd7b1b048 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lock955c98200 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter id=process700328 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processcd7b1b048 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lock83fd3b200 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter id=processffaef8 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processac352e9b8 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lock77b633580 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter id=process86a6ef8 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processcd7b1b048 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lockdc536d580 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter event=e_waitPipeGetRow type=consumer id=processcd7b1b048
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=process717198
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=processffaef8
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=process86a6478
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=processdc28aeef8
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=processce50ce088
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=process47eda8
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,exchangeEvent id=port80314690 nodeId=3
11/16/2011 20:37:59,spid20s,Unknown,waiter id=process717198 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processac352e9b8 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lock68f374980 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter id=process716c58 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processcd7b1b048 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lock60e8d8a80 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter id=process47f198 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processdc28aeef8 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lockb7c7f1c00 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter id=processdc28aeef8 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processac352e9b8 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lock7797b6500 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,waiter event=e_waitPipeGetRow type=consumer id=processac352e9b8
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=process6d5c18
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=process716c58
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=process478da8
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=process8691198
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=process86a6ef8
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=process700328
11/16/2011 20:37:59,spid20s,Unknown,owner event=e_waitNone type=producer id=process47f198
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,exchangeEvent id=port80315870 nodeId=3
11/16/2011 20:37:59,spid20s,Unknown,waiter id=process6d5c18 mode=U requestType=wait
11/16/2011 20:37:59,spid20s,Unknown,waiter-list
11/16/2011 20:37:59,spid20s,Unknown,owner id=processcd7b1b048 mode=U
11/16/2011 20:37:59,spid20s,Unknown,owner-list
11/16/2011 20:37:59,spid20s,Unknown,keylock hobtid=72057594060931072 dbid=5 objectname=MyServer_Database.dbo.DEXTable indexname=PK_DEXTable id=lock46a62fe00 mode=U associatedObjectId=72057594060931072
11/16/2011 20:37:59,spid20s,Unknown,resource-list
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=processdc28aeef8 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (d600a7d4a467) waittime=4836 ownerId=299785428 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.820 XDES=0xce4278410 lockMode=U schedulerid=8 kpid=15756 status=suspended spid=157 sbid=0 ecid=6 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.820 lastbatchcompleted=2011-11-16T20:37:53.807 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785428 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=processce50ce088 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (d1007416f809) waittime=5538 ownerId=299785428 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.820 XDES=0x946b46d30 lockMode=U schedulerid=4 kpid=20396 status=suspended spid=157 sbid=0 ecid=3 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.820 lastbatchcompleted=2011-11-16T20:37:53.807 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785428 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,Proc [Database Id = 5 Object Id = 957962489]
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=processcd7b1b048 taskpriority=0 logused=20003 waittime=4118 schedulerid=3 kpid=13252 status=suspended spid=157 sbid=0 ecid=0 priority=0 transcount=2 lastbatchstarted=2011-11-16T20:37:53.820 lastbatchcompleted=2011-11-16T20:37:53.807 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 loginname=IIS APPPOOL\MyServer_Database isolationlevel=read committed (2) xactid=299785428 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,Proc [Database Id = 5 Object Id = 957962489]
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=processac352e9b8 taskpriority=0 logused=20003 waittime=4071 schedulerid=10 kpid=20384 status=suspended spid=147 sbid=0 ecid=0 priority=0 transcount=2 lastbatchstarted=2011-11-16T20:37:53.823 lastbatchcompleted=2011-11-16T20:37:53.810 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 loginname=IIS APPPOOL\MyServer_Database isolationlevel=read committed (2) xactid=299785445 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=process86a6ef8 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (ab0001e10f4e) waittime=6099 ownerId=299785445 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.823 XDES=0xdb9b53cc0 lockMode=U schedulerid=11 kpid=17448 status=suspended spid=147 sbid=0 ecid=4 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.823 lastbatchcompleted=2011-11-16T20:37:53.810 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785445 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=process86a6478 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (7500c3691103) waittime=6099 ownerId=299785428 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.820 XDES=0xdb9b53a80 lockMode=U schedulerid=11 kpid=19324 status=suspended spid=157 sbid=0 ecid=7 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.820 lastbatchcompleted=2011-11-16T20:37:53.807 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785428 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=process8691198 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (d20082032104) waittime=6052 ownerId=299785445 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.823 XDES=0xabdc20870 lockMode=U schedulerid=10 kpid=24760 status=suspended spid=147 sbid=0 ecid=7 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.823 lastbatchcompleted=2011-11-16T20:37:53.810 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785445 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=processffaef8 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (f900d9903a2a) waittime=6099 ownerId=299785428 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.820 XDES=0xd9f26e080 lockMode=U schedulerid=9 kpid=16712 status=suspended spid=157 sbid=0 ecid=8 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.820 lastbatchcompleted=2011-11-16T20:37:53.807 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785428 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=process717198 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (4700497f7879) waittime=5959 ownerId=299785428 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.820 XDES=0x8006dcc0 lockMode=U schedulerid=6 kpid=7420 status=suspended spid=157 sbid=0 ecid=12 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.820 lastbatchcompleted=2011-11-16T20:37:53.807 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785428 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=process716c58 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (5a00f098709d) waittime=5928 ownerId=299785445 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.823 XDES=0x6c020d880 lockMode=U schedulerid=6 kpid=17856 status=suspended spid=147 sbid=0 ecid=11 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.823 lastbatchcompleted=2011-11-16T20:37:53.810 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785445 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=process700328 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (51003376bf57) waittime=6099 ownerId=299785445 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.823 XDES=0x92beba3d0 lockMode=U schedulerid=5 kpid=7004 status=suspended spid=147 sbid=0 ecid=3 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.823 lastbatchcompleted=2011-11-16T20:37:53.810 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785445 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=process6d5c18 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (150048fb6c35) waittime=5803 ownerId=299785445 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.823 XDES=0xdbadb2560 lockMode=U schedulerid=3 kpid=3824 status=suspended spid=147 sbid=0 ecid=12 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.823 lastbatchcompleted=2011-11-16T20:37:53.810 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785445 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=process47f198 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (4700c2a10b35) waittime=6037 ownerId=299785445 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.823 XDES=0x6c2da4080 lockMode=U schedulerid=2 kpid=8564 status=suspended spid=147 sbid=0 ecid=1 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.823 lastbatchcompleted=2011-11-16T20:37:53.810 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785445 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=process47eda8 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (2a004ee465b9) waittime=6099 ownerId=299785428 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.820 XDES=0x6c2da4870 lockMode=U schedulerid=2 kpid=24652 status=suspended spid=157 sbid=0 ecid=1 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.820 lastbatchcompleted=2011-11-16T20:37:53.807 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785428 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,inputbuf
11/16/2011 20:37:59,spid20s,Unknown,WHERE RespondentID = @RespondentID
11/16/2011 20:37:59,spid20s,Unknown,DELETE DEXTable WITH (ROWLOCK)
11/16/2011 20:37:59,spid20s,Unknown,frame procname=MyServer_Database.dbo.ClearDEXTableRows line=7 stmtstart=334 sqlhandle=0x03000500f958193991f66b01a29e00000100000000000000
11/16/2011 20:37:59,spid20s,Unknown,executionStack
11/16/2011 20:37:59,spid20s,Unknown,process id=process478da8 taskpriority=0 logused=0 waitresource=KEY: 5:72057594060931072 (1400c876e809) waittime=5709 ownerId=299785445 transactionname=DELETE lasttranstarted=2011-11-16T20:37:53.823 XDES=0x857272d30 lockMode=U schedulerid=1 kpid=7804 status=suspended spid=147 sbid=0 ecid=9 priority=0 transcount=0 lastbatchstarted=2011-11-16T20:37:53.823 lastbatchcompleted=2011-11-16T20:37:53.810 clientapp=.Net SqlClient Data Provider hostname=309389-DB13 hostpid=6536 isolationlevel=read committed (2) xactid=299785445 currentdb=5 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
11/16/2011 20:37:59,spid20s,Unknown,process-list
11/16/2011 20:37:59,spid20s,Unknown,deadlock victim=processdc28aeef8
11/16/2011 20:37:59,spid20s,Unknown,deadlock-list
11/16/2011 16:40:12,spid83,Unknown,DBCC TRACEON 1222<c/> server process ID (SPID) 83. This is an informational message only; no user action is required.

2
Bisakah Anda memastikan bahwa jejak bendera 1204 dihidupkan secara global "dbcc traceon (1204, -1)" dan memposting tangkapan itu setelah kebuntuan berikutnya.
mrdenny

Terima kasih atas umpan balik yang cepat dan bermanfaat! Ini sangat dihargai. Saya telah mengaktifkan jejak flag 1204 dan saya bergerak maju untuk membalikkan urutan PK ke (RespondentID, ExportID) dan menghapus petunjuk DELETE WITH (ROWLOCK). Mengenai menambahkan petunjuk MAXDOP 1, maksud Anda dalam prosedur InsertDEXTableRow atau ClearDEXTableRows? Dan jika harus masuk ke prosedur InsertDEXTableRow, apakah Anda pikir itu akan lebih efektif dalam satu blok UPSERT dibandingkan yang lain? (ada 3 alternatif UPSERT yang disarankan).
BobbyR-1of4

Sekali lagi, terima kasih atas umpan balik yang bagus ke posting saya: Saya telah maju dengan langkah-langkah berikut: • Membalikkan PK pada tabel DEXTable (RespondentID terlebih dahulu, lalu ExportID) untuk menghindari pemindaian tabel. • Membatalkan petunjuk ROWLOCK yang tidak perlu dalam prosedur ClearDEXTableRows. • Menggunakan pola upert safe safe (update atau insert) (opsi 1 direkomendasikan oleh Mark Storey-Smith) dalam prosedur InsertDEXTableRow.
BobbyR-1of4

lanjutan ... Sebelum melakukan perubahan, saya mengkonfirmasi bahwa aplikasi web saya tidak mengeluarkan pertanyaan apa pun pada tabel DEXTable dengan hanya ExportID di mana klausa atau INNER BERGABUNG tanpa terlebih dahulu menyaring oleh RespondentID. Saya mencari DB sql server dan basis kode (untuk referensi linq2sql, dll.). Urutan referensi kolom dalam klausa WHERE tidak masalah (yaitu WHERE ExportID = at-ExportID AND RespondentID = at-RespondentID versus WHERE RespondentID = at-RespondentID AND ExportID = at-ExportID), berdasarkan info yang saya temukan di googling tentang bahwa.
BobbyR-1of4

lanjutan ... Saya mengkonfirmasi bahwa rencana pelaksanaan sql berubah dari pemindaian menjadi pencarian setelah membalikkan urutan kolom FK dalam PK. Saya tidak menggunakan saran petunjuk MAXDOP 1, karena saya tidak yakin prosedur mana yang harus menggunakannya (ClearDEXTableRows atau InsertDEXTableRow) dan jika masih masuk akal diberikan opsi yang saya pilih (catat di atas).
BobbyR-1of4

Jawaban:


7

Tiga hal melompat:

  1. DELETE Anda ada di kolom ke-2 (RespondentID) dari PK saat ini yang berarti pemindaian, bukan pencarian.

  2. Petunjuk ROWLOCK tidak berguna

  3. Pola "UPSERT" Anda tidak aman untuk konkurensi. Tes keberadaan mungkin lulus untuk 2 utas yang tumpang tindih (dalam waktu) memberikan kesalahan.

Memperbaiki

  1. Membalikkan pesanan PK Anda di DEXTable ke (RespondentID, ExportID). Atau tambahkan indeks terpisah pada RespondentID saja. Secara pribadi, saya mungkin akan membalik urutan PK.

  2. Hapus petunjuk ROWLOCK. Jika terus berlanjut setelah perubahan indeks dan UPSERT yang disarankan di sini, coba UPDLOCK, tetapi hanya setelah memeriksa paralelisme

  3. Periksa paralelisme dalam rencana: coba MAXDOP 1 untuk membatasi. Coba ini sebelum UPDLOCK

  4. Gunakan pola UPSERT "JFDI". Artinya, INSERT tetap akan memeriksa keunikan jadi hanya INSERT, jika gagal maka UPDATE.

Untuk SQL Server 2005 (Anda akan menggunakan MERGE di SQL Server 2008+)

BEGIN TRY

    BEGIN TRY
        INSERT DEXTable (ExportID, RespondentID, Exported)
        VALUES (@ExportID, @RespondentID, getdate())
    END TRY
    BEGIN CATCH
        IF ERROR_NUMBER() = 2627
            UPDATE DEXTable
            SET Exported = getdate()
            WHERE ExportID = @ExportID AND RespondentID = @RespondentID
        ELSE
        BEGIN
           ..process real error
           RAISERROR (...)
        END
    END CATCH

END TRY
BEGIN CATCH
    ..process
    RAISERROR (...)
END CATCH

Akhirnya, MSDN merekomendasikan Anda untuk menjebak kesalahan jalan buntu dan mencoba kembali di sisi klien. Ini harus menjadi bagian dari lapisan akses data Anda yang menangani semua panggilan SQL Anda.


5

+1 untuk penjelasan @ gbn tentang kemungkinan penyebabnya, tetapi saya bukan penggemar pola INSERT / UPDATE yang disarankan, kecuali jika pembaruan benar-benar merupakan kasus luar biasa (yaitu 99,99% dari waktu penyisipan terjadi). Pendekatan pilihan saya selalu:

BEGIN TRANSACTION

UPDATE DEXTable WITH (UPDLOCK, HOLDLOCK)
SET Exported = getdate()
WHERE ExportID = @ExportID AND RespondentID = @RespondentID

IF (@@ROWCOUNT = 0)
BEGIN
    INSERT DEXTable (ExportID, RespondentID, Exported)
    VALUES (@ExportID, @RespondentID, getdate())
END

COMMIT TRANSACTION

Anda juga dapat mengurangi kebuntuan dengan menambahkan petunjuk ke permintaan Anda saat ini:

BEGIN TRANSACTION

IF NOT EXISTS (SELECT RespondentID FROM DEXTable WITH (UPDLOCK, HOLDLOCK) WHERE ExportID = @ExportID AND RespondentID = @RespondentID)
    BEGIN
      INSERT DEXTable
        (ExportID, RespondentID, Exported)
      VALUES
        (@ExportID, @RespondentID, getdate())
    END
    ELSE
    BEGIN
      UPDATE DEXTable
      SET Exported = getdate()
      WHERE ExportID = @ExportID AND RespondentID = @RespondentID
    END

COMMIT TRANSACTION

2

Tanpa info kebuntuan lagi saya hanya menebak di sini tapi ...

Tidak ada indeks pada kolom yang Anda gunakan temukan baris untuk dihapus. Ini berarti pemindaian indeks berkerumun setiap kali yang berarti banyak kunci ketika penghapusan dimulai. Meskipun Anda punya DENGAN (ROWLOCK) di sana masih perlu ada skema kunci di atas meja untuk memastikan tidak ada yang terjadi.

Coba tambahkan indeks pada kolom RespondentID dan lihat apakah itu memperbaiki masalah. Melihat rencana eksekusi sebelum dan sesudah indeks dibuat harus memberikan beberapa indikasi tentang masalah yang sedang diperbaiki juga.

Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.