Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Isolation levels Expand / Collapse
Author
Message
Posted Thursday, December 17, 2009 7:53 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, February 27, 2014 10:41 AM
Points: 361, Visits: 1,781

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.


Post #835691
Posted Thursday, December 17, 2009 7:56 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, August 1, 2014 8:28 AM
Points: 357, Visits: 910
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
Post #835692
Posted Thursday, December 17, 2009 8:08 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, February 27, 2014 10:41 AM
Points: 361, Visits: 1,781
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
Post #835700
Posted Thursday, December 17, 2009 8:13 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, August 1, 2014 8:28 AM
Points: 357, Visits: 910
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.
Post #835703
Posted Thursday, December 17, 2009 9:07 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Friday, August 15, 2014 11:42 AM
Points: 646, Visits: 732
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
Post #835755
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse