Как исправить тупики на 2 страницах? - PullRequest
0 голосов
/ 31 декабря 2018

У меня такая же ситуация, как this (есть ответ о PREFETCH, но ссылка для ответа - мусор. Я не могу найти хорошую статью об исправлении PREFETCH).

Псевдокод проблемного места:

foreach(var item in list)
{
var item2 = Select //use item info
Update // use item2 info
}

График

У меня есть идеи, чтобы избежать S-блокировок на страницах и строках: 1) транзакция моментального снимка 2) разрешить блокировку страницы: = false && SELECT WITH (UPDLOCK).

Но есть EF ORM и UoW-оболочка для контекста, и у меня есть некоторые трудности с реализацией идей.Mybee у вас есть лучшие идеи или можете лучше объяснить ситуацию.XML с измененными именами:

<deadlock-list>
 <deadlock victim="process804e6bc8">
  <process-list>
   <process id="process804e6bc8" taskpriority="0" logused="0" waitresource="PAGE: 10:1:1488426" waittime="2142" ownerId="564828035" transactionname="SELECT" lasttranstarted="2018-12-19T17:40:15.957" XDES="0xa1c62330" lockMode="S" schedulerid="7" kpid="86760" status="suspended" spid="208" sbid="2" ecid="0" priority="0" trancount="0" lastbatchstarted="2018-12-19T17:40:15.957" lastbatchcompleted="2018-12-19T17:40:15.957" clientapp=".Net SqlClient Data Provider" hostname="" hostpid="10652" loginname="name" isolationlevel="read committed (2)" xactid="564828035" currentdb="1" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
    <executionStack>
     <frame procname="adhoc" line="1" stmtstart="66" sqlhandle="0x02000000621f4424c6c29ec12837bc8a85df7a3c6a7ab140">
SELECT 
    [Project1].[Id] AS [Id], 
    [Project1].[xxx] AS [xxx], 
    [Project1].[yyyid] AS [yyyid], 
    [Project1].[vvv] AS [vvv], 
    [Project1].[fff] AS [fff], 
    [Project1].[lll] AS [lll], 
    [Project1].[ccc] AS [ccc], 
    [Project1].[mmm] AS [mmm]
    FROM ( SELECT 
        [Extent1].[Id] AS [Id], 
        [Extent1].[xxx] AS [xxx], 
        [Extent1].[yyyid] AS [yyyid], 
        [Extent1].[vvv] AS [vvv], 
        [Extent1].[fff] AS [fff], 
        [Extent1].[lll] AS [lll], 
        [Extent1].[ccc] AS [ccc], 
        [Extent1].[mmm] AS [mmm]
        FROM [dbo].[sss] AS [Extent1]
        WHERE ([Extent1].[Cl     </frame>
     <frame procname="unknown" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">
unknown     </frame>
    </executionStack>
    <inputbuf>
(@p__linq__0 int,@p__linq__1 int)SELECT 
    [Project1].[Id] AS [Id], 
    [Project1].[xxx] AS [xxx], 
    [Project1].[yyyid] AS [yyyid], 
    [Project1].[vvv] AS [vvv], 
    [Project1].[fff] AS [fff], 
    [Project1].[lll] AS [lll], 
    [Project1].[ccc] AS [ccc], 
    [Project1].[mmm] AS [mmm]
    FROM ( SELECT 
        [Extent1].[Id] AS [Id], 
        [Extent1].[xxx] AS [xxx], 
        [Extent1].[yyyid] AS [yyyid], 
        [Extent1].[vvv] AS [vvv], 
        [Extent1].[fff] AS [fff], 
        [Extent1].[lll] AS [lll], 
        [Extent1].[ccc] AS [ccc], 
        [Extent1].[mmm] AS [mmm]
        FROM [dbo].[sss] AS [Exte    </inputbuf>
   </process>
   <process id="process601ddc8" taskpriority="0" logused="1976" waitresource="PAGE: 10:1:1488427" waittime="2129" ownerId="564828018" transactionname="user_transaction" lasttranstarted="2018-12-19T17:40:15.913" XDES="0xdfb74e80" lockMode="IX" schedulerid="3" kpid="93564" status="suspended" spid="191" sbid="2" ecid="0" priority="0" trancount="2" lastbatchstarted="2018-12-19T17:40:15.977" lastbatchcompleted="2018-12-19T17:40:15.977" clientapp=".Net SqlClient Data Provider" hostname="" hostpid="10652" loginname="name" isolationlevel="read committed (2)" xactid="564828018" currentdb="1" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
    <executionStack>
     <frame procname="adhoc" line="1" stmtstart="140" stmtend="528" sqlhandle="0x02000000181bbd27d32bd4895ac7599f3d0749383576066e">
UPDATE [dbo].[sss]
SET [xxx] = @0, [yyyid] = @1, [vvv] = @2, [fff] = @3, [lll] = @4
WHERE ([Id] = @5)     </frame>
     <frame procname="unknown" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000">
unknown     </frame>
    </executionStack>
    <inputbuf>
(@0 int,@1 int,@2 nvarchar(32),@3 datetime2(7),@4 datetime2(7),@5 int)UPDATE [dbo].[sss]
SET [xxx] = @0, [yyyid] = @1, [vvv] = @2, [fff] = @3, [lll] = @4
WHERE ([Id] = @5)
SELECT [ccc], [mmm]
FROM [dbo].[sss]
WHERE @@ROWCOUNT &gt; 0 AND [Id] = @5    </inputbuf>
   </process>
  </process-list>
  <resource-list>
   <pagelock fileid="1" pageid="1488426" dbid="10" objectname="dbname.dbo.sss" id="lock12c525200" mode="IX" associatedObjectId="72057594551795712">
    <owner-list>
     <owner id="process601ddc8" mode="IX"/>
    </owner-list>
    <waiter-list>
     <waiter id="process804e6bc8" mode="S" requestType="wait"/>
    </waiter-list>
   </pagelock>
   <pagelock fileid="1" pageid="1488427" dbid="10" objectname="dbname.dbo.sss" id="lockc3cc5c80" mode="S" associatedObjectId="72057594551795712">
    <owner-list>
     <owner id="process804e6bc8" mode="S"/>
    </owner-list>
    <waiter-list>
     <waiter id="process601ddc8" mode="IX" requestType="wait"/>
    </waiter-list>
   </pagelock>
  </resource-list>
 </deadlock>
</deadlock-list>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...