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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

FROM dbo.Culture ;<br />

-- COMMIT;<br />

Listing 4.24: Tab 4, a query using READ_COMMITTED_SNAPSHOT isolation.<br />

159<br />

Chapter 4: Transactions<br />

So far, the queries return exactly the same results under either SNAPSHOT or READ_<br />

COMMITTED_SNAPSHOT mode. At this point, let's investigate current snapshot activity<br />

using our DMOs. The first simple query we can run is simply to get a count of currently<br />

active snapshots, from the sys.dm_tran_transactions_snapshot DMV, as shown<br />

in Listing 4.25.<br />

SELECT COUNT([transaction_sequence_num]) AS [snapshot transaction count]<br />

FROM sys.dm_tran_transactions_snapshot ;<br />

Listing 4.25: A count of currently active snapshot transactions.<br />

This returns a snapshot transaction count of two, since our SNAPSHOT query in Listing<br />

4.5 relies on the ultimate result of our two open transactions in Listings 4.21 (Tab 1) and<br />

4.22 (Tab 2). Next, let's interrogate the active_snapshot_database_transactions<br />

DMV, as shown in Listing 4.26.<br />

SELECT DTASDT.transaction_id ,<br />

DTASDT.session_id ,<br />

DTASDT.transaction_sequence_num ,<br />

DTASDT.first_snapshot_sequence_num ,<br />

DTASDT.commit_sequence_num ,<br />

DTASDT.is_snapshot ,<br />

DTASDT.elapsed_time_seconds ,<br />

DEST.text AS [command text]<br />

FROM sys.dm_tran_active_snapshot_database_transactions DTASDT<br />

INNER JOIN sys.dm_exec_connections DEC<br />

ON DTASDT.session_id = DEC.most_recent_session_id<br />

INNER JOIN sys.dm_tran_database_transactions DTDT<br />

ON DTASDT.transaction_id = DTDT.transaction_id

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

Saved successfully!

Ooh no, something went wrong!