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.

153<br />

Chapter 4: Transactions<br />

In other words, it returns records for all active transactions that either create or read row<br />

versions from the version store in tempdb. It is an instance-level view, and so will return<br />

rows for transactions using snapshot isolation for all databases on a given instance.<br />

However, version store usage is not limited to just sessions running under snapshot<br />

isolation, but also occurs as a result of triggers, online indexing, or the use of MARS<br />

(Multiple Active Results Sets – see Books Online for details). Triggers were the first <strong>SQL</strong><br />

<strong>Server</strong> construct to make use of row versioning. DML triggers make use of temporary,<br />

non-materialized tables that mimic the structure of the tables upon which they are based.<br />

There is both an inserted and a deleted table. The inserted table stores versions of<br />

the rows affected by an INSERT or UPDATE query; specifically, the new rows added to the<br />

underlying (trigger) table. The deleted table stores a copy of the records deleted from<br />

the underlying table via a DELETE statement. Both tables are hit in the case of an UPDATE<br />

statement, as an UPDATE is nothing more than a DELETE followed by an INSERT. The<br />

rows are first moved from the underlying table to the deleted "virtual table." Then the<br />

new rows are added to the inserted "virtual table" after being added to the underlying<br />

table. In the case of online indexing, available as a benefit of licensing Enterprise<br />

Edition <strong>SQL</strong> <strong>Server</strong> 2005 and 2008, row versioning is used to maintain concurrency<br />

during the online indexing process. All these transactions will be noted in a query<br />

against sys.dm_tran_active_snapshot_database_transactions.<br />

In terms of identifier columns, this DMV provides a transaction_id column,<br />

which identifies the transaction at the instance level and can be used to join to other<br />

transaction-related DMOs. It also provides a session_id column, which identifies the<br />

session <strong>with</strong> which the transaction is associated and can be used to join to executionrelated<br />

DMOs, as well as to spid in sys.sysprocesses. Other relevant columns<br />

include:<br />

• transaction_sequence_num – for transactions that access or modify the version<br />

store; this is a sequence number given to the transaction the first time it reads or<br />

writes to the version store; Transaction Sequence Numbers (XSNs) increment serially<br />

for each transaction

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

Saved successfully!

Ooh no, something went wrong!