Database Reference
In-Depth Information
Data Access, Modifications, and Transaction Lifetime
Although we have already discussed a few key elements used by in-memory OLTP to manage data access and the
concurrency model, let's review them here.
Global Transaction Timestamp
is an auto-incremented value that uniquely identifies every
transaction in the system. SQL Server increments this value at the transaction pre-commit stage.
TransactionId
is another identifier (timestamp), which also uniquely identifies a
transaction. SQL Server obtains and increments its value at the moment when the
transaction starts.
Every row has
BeginTs
and
EndTs
timestamps, which correspond to the
Global Transaction
Timestamp
of the transaction that created or deleted this version of a row.
Figure
32-17
shows the lifetime of a transaction that works with memory-optimized tables.
Figure 32-17.
Transaction lifetime
At the time when a new transaction starts, it generates a new
TransactionId
and obtains the current
Global
Transaction Timestamp
value. The
Global Transaction Timestamp
value dictates what version of the rows is visible to
the transaction and the timestamp value should be in between the
BeginTs
and
EndTs
for the row to be visible. During
data modifications, however, the transaction analyzes if there are any uncommitted versions of the rows, which
prevents write/write conflicts when multiple sessions modify the same data.
When a transaction needs to delete a row, it updates the
EndTs
timestamp with the
TransactionId
value, which
also has an indicator that the timestamp contains the
TransactionId
rather than the
Global Transaction Timestamp
.
The Insert operation creates a new row with the
BeginTs
of the
TransactionId
and the
EndTs
of
Infinity
. Finally, the
update operation consists of delete and insert operations internally.
Figure
32-18
shows the data rows after we created and populated the
dbo.HKData
table in Listing 32-7, assuming
that the rows were created by a transaction with the
Global Transaction Timestamp
of 5. (The hash index structure is
omitted for simplicity sake.)