SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Select statements causing locking???
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ferrethouse
Constraint Violating Yak Guru

303 Posts

Posted - 05/09/2012 :  12:11:28  Show Profile  Reply with Quote
We are using read committed snapshot isolation level so I thought reads couldn't cause locking. We seem to be getting a fair amount of it and the software I use to monitor it (Ignite) is reporting select statements (such as the one below) as the cause...


(@p0 datetime,@p1 datetime,@p2 datetime,@p3 datetime,@p4 datetime,@p5 datetime,@p6 int,@p7 int,@p8  
     int,@p9 int,@p10 int) 
SELECT COUNT(*) AS [value]  
FROM  
   (  
   SELECT  
      (  
      SELECT COUNT(*)  
      FROM [dbo].[Subscription] AS [t2]  
      LEFT OUTER JOIN [dbo].[Students] AS [t3]  
      ON [t3].[StudentsID] = [t2].[StudentsID]  
      LEFT OUTER JOIN [dbo].[Departments] AS [t4]  
      ON [t4].[DepartmentID] = [t3].[DepartmentID]  
      WHERE ([t2].[StartDate] >= @p0)  
     AND ([t2].[StartDate] < @p1)  
     AND ([t2].[CourseID] = [t0].[CourseID])  
      ) AS [value],  
      (  
      SELECT COUNT(*)  
      FROM [dbo].[Subscription] AS [t5]  
      LEFT OUTER JOIN [dbo].[Students] AS [t6]  
      ON [t6].[StudentsID] = [t5].[StudentsID]  
      LEFT OUTER JOIN [dbo].[Departments] AS [t7]  
      ON [t7].[DepartmentID] = [t6].[DepartmentID]  
      WHERE ((( SELECT MIN([t9].[ActivityStarted]) FROM [dbo].[Students] AS [t8], [dbo].[Activity]  
         AS [t9] WHERE ([t9].[StudentsID] = [t5].[StudentsID]) AND ([t9].[CourseID] = [t5]. 
         [CourseID]) AND ([t8].[StudentsID] = [t5].[StudentsID]) AND ([t9].[StudentsID] = [t8]. 
         [StudentsID]) )) >= @p2)  
     AND ((( SELECT MIN([t11].[ActivityStarted]) FROM [dbo].[Students] AS [t10], [dbo].[Activity]  
         AS [t11] WHERE ([t11].[StudentsID] = [t5].[StudentsID]) AND ([t11].[CourseID] = [t5]. 
         [CourseID]) AND ([t10].[StudentsID] = [t5].[StudentsID]) AND ([t11].[StudentsID] = [t10]. 
         [StudentsID]) )) < @p3)  
     AND ([t5].[CourseID] = [t0].[CourseID])  
      ) AS [value2],  
      (  
      SELECT COUNT(*)  
      FROM [dbo].[Subscription] AS [t12]  
      LEFT OUTER JOIN [dbo].[Students] AS [t13]  
      ON [t13].[StudentsID] = [t12].[StudentsID]  
      LEFT OUTER JOIN [dbo].[Departments] AS [t14]  
      ON [t14].[DepartmentID] = [t13].[DepartmentID]  
      WHERE ([t12].[Completed] >= @p4)  
     AND ([t12].[Completed] < @p5)  
     AND ([t12].[Status] = @p6)  
     AND ([t12].[CourseID] = [t0].[CourseID])  
      ) AS [value3], [t0] 
      .[ClientID]  
   FROM [dbo].[Courses] AS [t0]  
   LEFT OUTER JOIN [dbo].[CourseCategories] AS [t1]  
   ON [t1].[CourseCatID] = [t0].[CourseCatID]  
   ) AS [t15]  
WHERE (([t15].[value] > @p7)  
OR ([t15].[value3] > @p8)  
OR ([t15].[value2] > @p9))  
AND ([t15].[ClientID] = @p10)

ferrethouse
Constraint Violating Yak Guru

303 Posts

Posted - 05/15/2012 :  18:39:47  Show Profile  Reply with Quote
Nobody :(

It is LINQ. Is LINQ doing something behind the scenes? Maybe this isn't the correct forum to ask this question?
Go to Top of Page

Sachin.Nand
Flowing Fount of Yak Knowledge

2937 Posts

Posted - 05/15/2012 :  23:57:54  Show Profile  Reply with Quote
quote:
Originally posted by ferrethouse

Nobody :(

It is LINQ. Is LINQ doing something behind the scenes? Maybe this isn't the correct forum to ask this question?



Don't blame SQL Server for the mess LINQ creates..

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=172842#683538

After Monday and Tuesday even the calendar says W T F ....
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
6997 Posts

Posted - 05/16/2012 :  00:12:29  Show Profile  Reply with Quote
quote:
Originally posted by ferrethouse

Nobody :(

It is LINQ. Is LINQ doing something behind the scenes? Maybe this isn't the correct forum to ask this question?



Have you verified that it is actually running with the default read committed isolation level?



CODO ERGO SUM
Go to Top of Page

ferrethouse
Constraint Violating Yak Guru

303 Posts

Posted - 05/16/2012 :  00:48:35  Show Profile  Reply with Quote
quote:
Originally posted by Sachin.Nand

quote:
Originally posted by ferrethouse

Nobody :(

It is LINQ. Is LINQ doing something behind the scenes? Maybe this isn't the correct forum to ask this question?



Don't blame SQL Server for the mess LINQ creates..

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=172842#683538

After Monday and Tuesday even the calendar says W T F ....



I agree 100% about LINQ but it doesn't answer my question.
Go to Top of Page

ferrethouse
Constraint Violating Yak Guru

303 Posts

Posted - 05/16/2012 :  00:49:36  Show Profile  Reply with Quote
quote:
Originally posted by Michael Valentine Jones

quote:
Originally posted by ferrethouse

Nobody :(

It is LINQ. Is LINQ doing something behind the scenes? Maybe this isn't the correct forum to ask this question?



Have you verified that it is actually running with the default read committed isolation level?



CODO ERGO SUM



The data is running with read committed isolation. I don't know if something (LINQ or otherwise) is overriding that setting.
Go to Top of Page

Sachin.Nand
Flowing Fount of Yak Knowledge

2937 Posts

Posted - 05/16/2012 :  01:46:41  Show Profile  Reply with Quote
Can you change that part of LINQ to a SP and check whether the the behavior is repeated ?

After Monday and Tuesday even the calendar says W T F ....
Go to Top of Page

ferrethouse
Constraint Violating Yak Guru

303 Posts

Posted - 05/16/2012 :  11:25:07  Show Profile  Reply with Quote
quote:
Originally posted by Sachin.Nand

Can you change that part of LINQ to a SP and check whether the the behavior is repeated ?

After Monday and Tuesday even the calendar says W T F ....



Yeah - we can do that. Unfortunately the example I posted was just one of many cases where it happens. It is a pretty major undertaking to get rid of LINQ completely but focusing on the big ones that are associated with locking would be a logical step.

Thanks.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
6997 Posts

Posted - 05/16/2012 :  23:47:05  Show Profile  Reply with Quote
quote:
Originally posted by ferrethouse

quote:
Originally posted by Michael Valentine Jones

quote:
Originally posted by ferrethouse

Nobody :(

It is LINQ. Is LINQ doing something behind the scenes? Maybe this isn't the correct forum to ask this question?



Have you verified that it is actually running with the default read committed isolation level?



CODO ERGO SUM



The data is running with read committed isolation. I don't know if something (LINQ or otherwise) is overriding that setting.



There is a good chance that the software you are using will identify the isolation level of the blocking query.



CODO ERGO SUM
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.1 seconds. Powered By: Snitz Forums 2000