SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Isolation levels


Isolation levels

Author
Message
HBK_4700
HBK_4700
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2087 Visits: 1839
I am trying to understand the below script to find out the long/slow running sql statement.

http://www.sqlservercentral.com/articles/DMV/64425/

BEGIN
-- Do not lock anything, and do not get held up by any locks.
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

-- What SQL Statements Are Currently Running?
SELECT [Spid] = session_Id
, ecid
, [Database] = DB_NAME(sp.dbid)
, [User] = nt_username
, [Status] = er.status
, [Wait] = wait_type
, [Individual Query] = SUBSTRING (qt.text,
er.statement_start_offset/2,
(CASE WHEN er.statement_end_offset = -1
THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
ELSE er.statement_end_offset END -
er.statement_start_offset)/2)
,[Parent Query] = qt.text
, Program = program_name
, Hostname
, nt_domain
, start_time
FROM sys.dm_exec_requests er
INNER JOIN sys.sysprocesses sp ON er.session_id = sp.spid
CROSS APPLY sys.dm_exec_sql_text(er.sql_handle)as qt
WHERE session_Id > 50 -- Ignore system spids.
AND session_Id NOT IN (@@SPID) -- Ignore this current statement.
ORDER BY 1, 2
END


Now my question is:- is there any impact on production database, because we are using read uncommited isolation level.
NickDBA
NickDBA
SSC Eights!
SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)

Group: General Forum Members
Points: 851 Visits: 939
No, the READ UNCOMMITTED is used so the query doesn't have an impact. It doesn't care about locks and places none of its own
HBK_4700
HBK_4700
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2087 Visits: 1839
BaddaBing (12/17/2009)
No, the READ UNCOMMITTED is used so the query doesn't have an impact. It doesn't care about locks and places none of its own


Thanks for your reply. So setting isolation level to read uncommited is for only this query?

or do we need to change Isolation level to read commited again after executing this query
NickDBA
NickDBA
SSC Eights!
SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)SSC Eights! (851 reputation)

Group: General Forum Members
Points: 851 Visits: 939
Depends on what you're doing. Yes, the isolation level set is just for that session / connection until you specify otherwise, it does not have an affect on other queries running in other sessions etc. The question is, are you doing anything else in that session after you run this query that needs to change the isolation level? If so, then do another SET ISOLATION LEVEL...to a level that fulfills the requirement.
MannySingh
MannySingh
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3065 Visits: 787
Here is some more info of your interest.

Query with TEXT and average CPU time for the top five queries.
SELECT TOP 5 total_worker_time/execution_count AS [Avg CPU Time],
SUBSTRING(st.text, (qs.statement_start_offset/2)+1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
ELSE qs.statement_end_offset
END - qs.statement_start_offset)/2) + 1) AS statement_text
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
ORDER BY total_worker_time/execution_count DESC;

This was taken from http://msdn.microsoft.com/en-us/library/ms181929.aspx

or a simple version such as this one to find the text of all queries with latest Query on top.

Select s.text,* from sys.sysprocesses p
Cross apply sys.dm_exec_sql_text (p.sql_handle) s
where p.spid >50
and p.spid not in (select @@spid)
Order by p.last_batch desc

Or
DECLARE @spid int
SET @spid = (SELECT top 1 SPID from master..sysprocesses order by last_batch desc)
DBCC INPUTBUFFER (@spid)

OR
DECLARE @spid int
DECLARE @handle binary(20)
SET @spid = (SELECT top 1 SPID from master..sysprocesses order by last_batch desc)
SET @handle = (SELECT sql_handle from master..sysprocesses where spid = @spid)
SELECT * FROM ::fn_get_sql(@Handle)

for more infor about the ISOLATION and Lock HINTS http://dbanation.com/?p=114

Maninder
www.dbanation.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search