Necesita ayuda Solución de problemas de SQL Server 2005 Deadlock Scenario


9

Me encuentro con un escenario de punto muerto en el que los únicos participantes en el punto muerto parecen ser una sola tabla y un único procedimiento almacenado que se elimina de esa tabla. Llegué a esa conclusión basándome en mi análisis del registro de errores sql en el momento de varios de estos puntos muertos, utilizando el artículo de MSDN a continuación como una guía para descifrar la traza en el registro de errores.

La tabla DEXTable y el procedimiento almacenado ClearDEXTableRows se definen a continuación. Hay otro procedimiento almacenado InsertDEXTableRow que inserta filas en DEXTable, pero ese proceso no parece estar involucrado en el punto muerto basado en las entradas en el registro de errores de SQL.

La DEXTable tiene ~ 8.3 millones de filas y tiende a crecer de manera constante. La tabla de encuestados también es grande y tiende a crecer de manera constante.

Se accede desde un sitio web de alto volumen de tráfico con páginas que con frecuencia llaman ClearDEXTableRows e InsertDEXTableRow en rápida sucesión.

El punto muerto ha ocurrido entre 0 y 9 veces por día durante los últimos 10 días.

He habilitado sql trace para 1222 (usando DBCC TRACEON 1222) y recientemente habilité el indicador 1204. Hay una buena descripción de la salida de estos indicadores en Detección y finalización de puntos muertos

Mis preguntas son:

¿Tiene sentido que solo este procedimiento almacenado ClearDEXTableRows sea la causa del punto muerto?

Si es así , ¿alguien puede ofrecer una buena explicación de cómo puede suceder esto y recomendar una forma de solucionarlo?
Mi sospecha es que las declaraciones DELETE están causando contención en el PK para DEXTable que debe reconstruirse con frecuencia.

Si no , ¿qué rastro adicional debo permitir para profundizar en la causa del punto muerto? (Quiero aprender aquí)

-- 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

Y aquí están algunas de las entradas de registro (no estoy completamente seguro de qué es útil)

-- 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
¿Puede asegurarse de que el indicador de traza 1204 esté activado globalmente "dbcc traceon (1204, -1)" y publique esa captura después del siguiente punto muerto?
mrdenny

¡Gracias a todos por los comentarios rápidos y útiles! Es muy apreciado. He habilitado el indicador de traza 1204 y estoy avanzando para revertir el orden PK a (RespondentID, ExportID) y eliminar la sugerencia DELETE WITH (ROWLOCK). Con respecto a agregar la sugerencia MAXDOP 1, ¿quiere decir dentro del procedimiento InsertDEXTableRow o ClearDEXTableRows? Y si entrara en el procedimiento InsertDEXTableRow, ¿cree que será más efectivo dentro de un bloque UPSERT frente a otro? (se sugirieron 3 alternativas UPSERT).
BobbyR-1 de 4

Nuevamente, agradezco la excelente respuesta a mi publicación: he seguido con los siguientes pasos: • Invertí la PK en la tabla DEXTable (RespondentID primero, luego ExportID) para evitar escaneos de tabla. • Se descartó una sugerencia ROWLOCK innecesaria en el procedimiento ClearDEXTableRows. • Se utilizó un patrón de inserción segura (actualización o inserción) de concurrencia (opción 1 recomendada por Mark Storey-Smith) en el procedimiento InsertDEXTableRow.
BobbyR-1 de 4

continúa ... Antes de realizar los cambios, confirmé que mi aplicación web no estaba emitiendo ninguna consulta en la tabla DEXTable con solo el ExportID en la cláusula where o INNER JOINs sin primero filtrar por RespondentID. Busqué tanto la base de datos del servidor sql como la base del código (para referencias de linq2sql, etc.). El orden de las referencias de columna en la cláusula WHERE no debería importar (es decir, WHERE ExportID = at-ExportID AND RespondentID = at-RespondentID versus WHERE RespondentID = at-RespondentID AND ExportID = at-ExportID), según la información que encontré buscando en Google ese.
BobbyR-1of4

continúa ... Confirmé que los planes de ejecución de SQL cambiaron de escaneos a búsquedas después de revertir el orden de la columna FK dentro del PK. No utilicé la sugerencia de sugerencia MAXDOP 1, ya que no estoy seguro de qué procedimiento debería usarla (ClearDEXTableRows o InsertDEXTableRow) y si aún tiene sentido dada la opción que elegí (mencionada anteriormente).
BobbyR-1 de 4

Respuestas:


7

Saltan tres cosas:

  1. Su DELETE está en la segunda columna (RespondentID) de la PK actual, lo que significa un escaneo, no una búsqueda.

  2. Sugerencia de ROWLOCK sin sentido

  3. Su patrón "UPSERT" no es seguro para la concurrencia. La prueba de existencia puede pasar por 2 hilos concurrentes superpuestos (en el tiempo) que dan un error.

Arreglar

  1. Invierta su orden PK en DEXTable a (RespondentID, ExportID). O agregue un índice separado solo en RespondentID. Personalmente, probablemente revertiría el orden de PK.

  2. Eliminar la pista ROWLOCK. Si continúa después de los cambios de índice y UPSERT sugeridos aquí, intente UPDLOCK, pero solo después de verificar el paralelismo

  3. Verifique el paralelismo en el plan: intente MAXDOP 1 para restringir. Prueba esto antes de UPDLOCK

  4. Use el patrón UPSERT "JFDI". Es decir, INSERT verificará la unicidad de todos modos, así que solo INSERTAR, si falla, ACTUALIZAR.

Para SQL Server 2005 (usaría MERGE en 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

Finalmente, MSDN recomienda que atrape los errores de punto muerto y vuelva a intentarlo en el lado del cliente. Esto debería formar parte de su capa de acceso a datos que maneja todas sus llamadas SQL.


5

+1 para la explicación de @ gbn de la causa probable, pero no soy fanático del patrón INSERT / UPDATE sugerido, a menos que una actualización sea realmente el caso excepcional (es decir, el 99.99% de las veces que ocurre una inserción). Mi enfoque preferido siempre ha sido:

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

También puede aliviar el estancamiento agregando sugerencias a su consulta actual:

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

Sin más información de punto muerto, solo adivino aquí, pero ...

No hay índice en la columna que está utilizando, busque las filas para eliminar. Esto significa un análisis de índice agrupado cada vez, lo que significa muchos bloqueos cuando comienza la eliminación. A pesar de que tiene WITH (ROWLOCK) allí, todavía debe haber bloqueos de esquema en la mesa para asegurarse de que no esté sucediendo nada.

Intente agregar un índice en la columna RespondentID y vea si eso soluciona el problema. Mirar el plan de ejecución antes y después de que se cree ese índice debería dar alguna indicación sobre el problema que también se está solucionando.

Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.