30.06.2013 Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2: Connections, Sessions and Requests<br />

Listing 2.1: Running the query against sysprocesses.<br />

Now, also in Tab #1, run the equivalent query against sys.dm_exec_requests.<br />

SELECT session_id ,<br />

command ,<br />

sql_handle<br />

FROM sys.dm_exec_requests<br />

WHERE DB_NAME(database_id) = 'SimpleTalk'<br />

Listing 2.2: Running the query against sys.dm_exec_requests.<br />

In sysprocesses, the sql_handle is available at session-scope and so we see an entry<br />

for the "empty session" (Tab #2) as well as for the query being executed in the current<br />

session. With sys.dm_exec_requests, a request is only observable while the query<br />

engine is processing each transaction associated <strong>with</strong> it. Once the final commit for the<br />

last transaction associated <strong>with</strong> the request is made, the request is no more. Thus, the<br />

second idle session is invisible to sys.dm_exec_requests, since no requests are<br />

currently being processed.<br />

Furthermore, sql_handle is not available from sys.dm_exec_sessions, so we could<br />

not run the equivalent query against that view. Both sysprocesses and sys.dm_exec_<br />

requests will, of course, detect currently executing queries, but, interestingly, if the<br />

second session (56) contained, for example, a modification that had completed, but not<br />

committed (or rolled back), then it would not be detected by a simple query against<br />

sys.dm_exec_requests.<br />

36

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!