我在存储过程中的查询下面运行,并遇到死锁错误。有人可以建议如何避免死锁吗?
UPDATE dr_importmmrdataaudit MMRAD
INNER JOIN dr_importmmrdata MMR
ON ( MMRAD.applicationId = MMR.applicationId
AND MMRAD.milestone = MMR.milestone )
SET MMRAD.isUpdated = 1
WHERE MMR.cimInvoiceStage <> 'Completed'
AND MMRAD.processId = processId;
UPDATE dr_importmmrdata MMR
INNER JOIN dr_importmmrdataaudit MMRAD
ON ( MMRAD.applicationId = MMR.applicationId
AND MMRAD.milestone = MMR.milestone )
SET MMR.fundingStatus = MMRAD.fundingStatus,
MMR.applicationPool = MMRAD.applicationPool,
MMR.taskOrderDescription = MMRAD.taskOrderDescription,
MMR.taskOrderPoolMatch = MMRAD.taskOrderPoolMatch,
MMR.milestone = MMRAD.milestone,
MMR.milestoneAchDate = MMRAD.milestoneAchDate,
MMR.cimFolderId = MMRAD.cimFolderId,
MMR.invoiceDate = MMRAD.invoiceDate,
MMR.milestoneCost = MMRAD.milestoneCost,
MMR.bpStartDate = MMRAD.bpStartDate,
MMR.bpEndDate = MMRAD.bpEndDate,
MMR.program = MMRAD.program,
MMR.lmiUn = MMRAD.lmiUn,
MMR.currentContractor = MMRAD.currentContractor,
MMR.cimInvoiceStage = MMRAD.cimInvoiceStage,
MMR.lastUploadedBy = user,
MMR.lastUploadedOn = Now()
WHERE MMR.cimInvoiceStage <> 'Completed'
AND MMRAD.processId = processId;
UPDATE dr_importmmrdataaudit
SET isInserted = 1
WHERE applicationId NOT IN (SELECT applicationId
FROM dr_importmmrdata)
AND processId = processId;
INSERT INTO dr_importmmrdata
(reportType,
applicationId,
applicationIdFK,
milestone,
fundingStatus,
applicationPool,
taskOrderDescription,
taskOrderPoolMatch,
milestoneAchDate,
cimFolderId,
invoiceDate,
milestoneCost,
bpStartDate,
bpEndDate,
program,
lmiUn,
currentContractor,
cimInvoiceStage,
uploadedBy,
uploadedOn,
lastUploadedBy,
lastUploadedOn)
SELECT reportType,
applicationId,
applicationIdFK,
milestone,
fundingStatus,
applicationPool,
taskOrderDescription,
taskOrderPoolMatch,
milestoneAchDate,
cimFolderId,
invoiceDate,
milestoneCost,
bpStartDate,
bpEndDate,
program,
lmiUn,
currentContractor,
cimInvoiceStage,
user,
Now(),
user,
Now()
FROM dr_importmmrdataaudit
WHERE applicationId NOT IN (SELECT applicationId
FROM dr_importmmrdata)
AND processId = processId;
如何避免在尝试获取锁时发现MySQL'Deadlock;尝试重新开始交易”