You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: samples/features/optimized-locking/transaction-id-locking/README.md
+20-16Lines changed: 20 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
4
4
# Optimized Locking: Transaction ID (TID) locking internals
5
5
6
-
This sample describes how to read and interpret the Transaction ID stored in row data pages.
6
+
This sample describes how to read and interpret the Transaction ID (TID) stored in row data pages.
7
7
8
8
## Background
9
9
@@ -17,15 +17,15 @@ Optimized Locking is based on two key mechanisms:
17
17
- Transaction ID (TID) locking
18
18
- Lock After Qualification (LAQ)
19
19
20
-
### What is the Transaction ID?
20
+
### What is the Transaction ID (TID)?
21
21
22
22
The Transaction ID (TID) is a unique transaction identifier.
23
23
24
24
When a [row-versioning based isolation level](https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-transaction-locking-and-row-versioning-guide#Row_versioning) is active, or when [Accelerated Database Recovery (ADR)](https://learn.microsoft.com/sql/relational-databases/accelerated-database-recovery-concepts) is enabled, every row in the database internally contains a transaction identifier.
25
25
26
26
The TID is stored on disk in the additional 14 bytes that are associated with each row when features such as RCSI or ADR are enabled.
27
27
28
-
Every transaction that modifies a row, it tags that row with its own TID, so each row in the database is labeled with the last TID that modified it.
28
+
Every transaction that modifies a row tags that row with its own TID, so each row in the database is labeled with the last TID that modified it.
29
29
30
30
### Contents
31
31
@@ -59,15 +59,15 @@ To run this sample, you need the following prerequisites.
59
59
60
60
### Setup code
61
61
62
-
1. Download [create-configure-optimizedlocking-db.sql](sql-scripts) T-SQL script from sql-scripts folder
63
-
2.Check if a database called OptimizedLocking does not exist in your SQL Server instance
62
+
1. Download [create-configure-optimizedlocking-db.sql](sql-scripts/create-configure-optimizedlocking-db.sql) T-SQL script from sql-scripts folder
63
+
2.Verify that a database named OptimizedLocking does not already exist in your SQL Server instance
64
64
3. Execute create-configure-optimizedlocking-db.sql script on your SQL Server instance
65
65
4. Run the commands described in the sample details section
66
66
67
67
<aname=sample-details></a>
68
68
## Sample Details
69
69
70
-
Currently, the only way to read the Transaction ID of a row is by using the `DBCC PAGE` command.
70
+
Currently, the only way to read the TID of a row is by using the `DBCC PAGE` command.
71
71
72
72
Let's consider the table dbo.TelemetryPacket, with the schema defined in the following T-SQL code snippet.
73
73
@@ -108,30 +108,32 @@ FROM
108
108
dbo.TelemetryPacket;
109
109
```
110
110
111
-
The output is similar to the following, except to the values in PageId column.
111
+
The output is similar to the following, except for the values in the PageId column.
112
112
113
113
| PageId | PacketID | Device |
114
114
| ----------- | --------- | --------- |
115
115
| (1:2456:0) | 1 | Something |
116
116
| (1:2457:0) | 2 | Something |
117
117
| (1:2458:0) | 3 | Something |
118
118
119
-
The values shown in the PageId column represent the physical location of the data.
119
+
Each value in the PageId column follows the format **(FileID:PageID:SlotID)** and represents the physical location of the data.
120
120
121
-
Let's look at the row where PacketID equals 1.
122
-
123
-
The value (1:2456:0) in the PageId column is composed of three parts separated by ":". Here is what each part represents:
124
-
- 1 is the numeric identifier of the database file (file number) where the page is located
125
-
- 2456 is the page number inside file 1 of the database
126
-
- 0 is the slot number
121
+
Let's examine the row where PacketID equals 1. The value (1:2456:0) is composed of three parts separated by ":". Here is what each part represents:
122
+
-**1** - the numeric identifier of the database file (FileID)
123
+
-**2456** - the page number within the file (PageID)
124
+
-**0** - the slot number on the page (SlotID)
127
125
128
126
Use the `DBCC PAGE` command to inspect the TID of page 2456.
129
127
130
128
```sql
129
+
-- Enable trace flag for DBCC PAGE output
130
+
DBCC TRACEON(3604);
131
+
GO
132
+
131
133
DBCC PAGE ('OptimizedLocking', 1, 2456, 3);
132
134
```
133
135
134
-
The value of the unique transaction identifier (TID) that modified the row with PacketID equal to 1 is in the **Version Information** section, under the **Transaction Timestamp** attribute, as shown in the following sample data.
136
+
The value of the unique TID that modified the row with PacketID equal to 1 is in the **Version Information** section, under the **Transaction Timestamp** attribute, as shown in the following sample data.
135
137
136
138
```sql
137
139
Version Information =
@@ -151,7 +153,9 @@ TID 985 represents the identifier of the transaction that inserted the rows; eve
151
153
152
154
The code included in this sample is not intended to be a set of best practices on how to build scalable enterprise grade applications. This is beyond the scope of this sample.
153
155
156
+
> **Note:** The `DBCC PAGE` command is undocumented and intended for troubleshooting and diagnostic purposes only. It should not be used in production environments without proper understanding and testing.
0 commit comments