SQL Server更新语句中的死锁问题

时间:2018-10-25 16:32:56

标签: sql sql-server

我在SQL Server的更新语句中遇到钥匙锁死锁问题。我在主键上有一个聚集索引,并且在where子句中使用它们。我可以肯定地说,这两个进程不会像这样编写Java代码那样更新同一行。他们正在尝试更新不同的行,但是仍然出现这种死锁。这两个过程都是X的所有者模式,并且根据图形请求U锁定。我也可以分享。

<deadlock-list>
<deadlock victim="process147029c28">
<process-list>
<process id="process147029c28" taskpriority="0" logused="1300" 
waitresource="KEY: 7:72057600641925120 (ef40b100fec4)" waittime="6363" 
ownerId="7750344" transactionname="implicit_transaction" 
lasttranstarted="2018-10-25T21:52:35.553" XDES="0x10006ad90" lockMode="U" 
schedulerid="3" kpid="17860" status="suspended" spid="67" sbid="0" ecid="0" 
priority="0" trancount="2" lastbatchstarted="2018-10-25T21:52:36.567" 
lastbatchcompleted="2018-10-25T21:52:36.540" lastattention="1900-01- 
01T00:00:00.540" clientapp="Microsoft JDBC Driver for SQL Server" 
hostname="USGURBHABISHT9" hostpid="0" loginname="bharat" 
isolationlevel="read committed (2)" xactid="7750344" currentdb="7" 
lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
</executionStack>
<inputbuf>
(@P0 nvarchar(4000),@P1 datetime2,@P2 nvarchar(4000),@P3 varchar(8000),@P4 
varchar(8000),@P5 nvarchar(4000),@P6 nvarchar(4000),@P7 datetime2,@P8 
nvarchar(4000),@P9 varchar(8000),@P10 nvarchar(4000),@P11 
varchar(8000),@P12 bigint,@P13 varchar(8000),@P14 varchar(8000),@P15 
nvarchar(4000),@P16 varchar(8000),@P17 datetime2,@P18 nvarchar(4000),@P19 
nvarchar(4000),@P20 nvarchar(4000),@P21 varchar(8000),@P22 
nvarchar(4000),@P23 nvarchar(4000),@P24 nvarchar(4000),@P25 
nvarchar(4000),@P26 nvarchar(4000),@P27 nvarchar(4000),@P28 bigint,@P29 
nvarchar(4000),@P30 nvarchar(4000),@P31 nvarchar(4000),@P32 
nvarchar(4000),@P33 nvarchar(4000),@P34 nvarchar(4000))Update 
IN_R_AU_MEM_ELIG_DTL set APPROVAL_CODE = @P0, ARCHIVE_DT = @P1, 
CASE_NUMBER = @P2, CATEGORY_CODE = @P3, CG_STATUS_CODE = @P4, CLOSE_DATE = 
@P5, CLOSURE_CODE = @P6, CREATE_DT = @P7, CREATE_USER_ID = @P8, 
DELETE_INDICATOR = @P9, ELIGIBILITY_SEQUENCE_NUMBER = @P10, 
ELIG_INCAR_FLAG = @P11, HISTORY_SEQ = @P12, INCARCERATION_CODE = @P13, 
INCARCERATION_DISCHARGE_DATE =    </inputbuf>
</process>
<process id="process13e98b088" taskpriority="0" logused="1992" 
waitresource="KEY: 7:72057600641925120 (f128991fbbbb)" waittime="6349" 
ownerId="7751290" transactionname="implicit_transaction" 
lasttranstarted="2018-10-25T21:52:35.803" XDES="0x12f960d90" lockMode="U" 
schedulerid="3" kpid="6176" status="suspended" spid="66" sbid="0" ecid="0" 
priority="0" trancount="2" lastbatchstarted="2018-10-25T21:52:36.610" 
lastbatchcompleted="2018-10-25T21:52:36.603" lastattention="1900-01- 
01T00:00:00.603" clientapp="Microsoft JDBC Driver for SQL Server" 
hostname="USGURBHABISHT9" hostpid="0" loginname="bharat" 
isolationlevel="read committed (2)" xactid="7751290" currentdb="7" 
lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
<inputbuf>
(@P0 nvarchar(4000),@P1 datetime2,@P2 nvarchar(4000),@P3 varchar(8000),@P4 
varchar(8000),@P5 nvarchar(4000),@P6 nvarchar(4000),@P7 datetime2,@P8 
nvarchar(4000),@P9 varchar(8000),@P10 nvarchar(4000),@P11 
varchar(8000),@P12 bigint,@P13 varchar(8000),@P14 varchar(8000),@P15 
nvarchar(4000),@P16 varchar(8000),@P17 datetime2,@P18 nvarchar(4000),@P19 
nvarchar(4000),@P20 nvarchar(4000),@P21 varchar(8000),@P22 
nvarchar(4000),@P23 nvarchar(4000),@P24 nvarchar(4000),@P25 
nvarchar(4000),@P26 nvarchar(4000),@P27 nvarchar(4000),@P28 bigint,@P29 
nvarchar(4000),@P30 nvarchar(4000),@P31 nvarchar(4000),@P32 
nvarchar(4000),@P33 nvarchar(4000),@P34 nvarchar(4000))Update 
IN_R_AU_MEM_ELIG_DTL set APPROVAL_CODE = @P0, ARCHIVE_DT = @P1, 
CASE_NUMBER = @P2, CATEGORY_CODE = @P3, CG_STATUS_CODE = @P4, CLOSE_DATE = 
@P5, CLOSURE_CODE = @P6, CREATE_DT = @P7, CREATE_USER_ID = @P8, 
DELETE_INDICATOR = @P9, ELIGIBILITY_SEQUENCE_NUMBER = @P10, 
ELIG_INCAR_FLAG = @P11, HISTORY_SEQ = @P12, INCARCERATION_CODE = @P13, 
INCARCERATION_DISCHARGE_DATE =    </inputbuf>
</process>
</process-list>
<resource-list>
<keylock hobtid="72057600641925120" dbid="7" 
objectname="IEWP_EE.dbo.IN_R_AU_MEM_ELIG_DTL" 
indexname="IN_R_AU_MEM_ELIG_DTL_PK" id="lock104f34d00" mode="X" 
associatedObjectId="72057600641925120">
<owner-list>
<owner id="process13e98b088" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="process147029c28" mode="U" requestType="wait"/>
</waiter-list>
</keylock>
<keylock hobtid="72057600641925120" dbid="7" 
objectname="IEWP_EE.dbo.IN_R_AU_MEM_ELIG_DTL" 
indexname="IN_R_AU_MEM_ELIG_DTL_PK" id="lock12ac42100" mode="X" 
associatedObjectId="72057600641925120">
<owner-list>
<owner id="process147029c28" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="process13e98b088" mode="U" requestType="wait"/>
</waiter-list>
</keylock>
</resource-list>
</deadlock>
</deadlock-list>


Update statement:

Update table_name updating all the columns even the primary key
where 1=1  
AND PERSON_NUMBER = '7769999750768'
AND TYPE_CASE_CODE = '550'  
AND START_DATE = '20180901' 
AND INCARCERATION_ADMIT_DATE = '00000000' 
AND OSS_AMOUNT = '000'
AND AID_CATEGORY = '50' 

Columns used in the where clause are the composite primary key.
And two update queries deadlocking  are having different primary key values.
So how it can have a lock on primary key?

表架构:

CREATE TABLE [dbo].[IN_R_AU_MEM_ELIG_DTL](
[CREATE_USER_ID] [varchar](20) NOT NULL,
[CREATE_DT] [datetime] NOT NULL,
[UNIQUE_TRANS_ID] [bigint] NOT NULL,
[HISTORY_SEQ] [bigint] NOT NULL,
[RECORD_TYPE] [varchar](1) NULL,
[SUB_RECORD_TYPE] [varchar](1) NULL,
[RECORD_SEQUENCE] [varchar](9) NULL,
[PERSON_NUMBER] [varchar](13) NOT NULL,
[PERSON_SEQUENCE] [varchar](8) NULL,
[ELIGIBILITY_SEQUENCE_NUMBER] [varchar](5) NULL,
[CASE_NUMBER] [varchar](13) NULL,
[CATEGORY_CODE] [varchar](2) NULL,
[TYPE_CASE_CODE] [varchar](3) NOT NULL,
[START_DATE] [varchar](8) NOT NULL,
[CLOSE_DATE] [varchar](8) NULL,
[APPROVAL_CODE] [varchar](3) NULL,
[CLOSURE_CODE] [varchar](3) NULL,
[DELETE_INDICATOR] [varchar](1) NULL,
[INCARCERATION_CODE] [varchar](1) NULL,
[INCARCERATION_ADMIT_DATE] [varchar](8) NOT NULL,
[INCARCERATION_DISCHARGE_DATE] [varchar](8) NULL,
[INCARCERATION_ELIG_FLAG] [varchar](1) NULL,
[RENEWAL_DATE] [varchar](8) NULL,
[RENEWAL_CODE] [varchar](2) NULL,
[PRE_RELEASE_DATE] [varchar](8) NULL,
[LOCATION_CODE] [varchar](4) NULL,
[MONEY_CODE] [varchar](1) NULL,
[OSS_AMOUNT] [varchar](5) NOT NULL,
[AID_CATEGORY] [varchar](10) NOT NULL,
[CG_STATUS_CODE] [varchar](5) NULL,
[MMIS_SND_PERSON_SEQ_NUM] [varchar](15) NULL,
[PROCESS_SW] [varchar](1) NULL,
[ELIG_INCAR_FLAG] [varchar](1) NULL,
[ARCHIVE_DT] [datetime] NULL,
[ROWID] [uniqueidentifier] NOT NULL DEFAULT (newid()),
[MMIS_SND_DT] [datetime] NULL,
CONSTRAINT [IN_R_AU_MEM_ELIG_DTL_PK] PRIMARY KEY CLUSTERED 
(
[INCARCERATION_ADMIT_DATE] ASC,
[AID_CATEGORY] ASC,
[OSS_AMOUNT] ASC,
[PERSON_NUMBER] ASC,
[START_DATE] ASC,
[TYPE_CASE_CODE] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]

0 个答案:

没有答案