[SQL Server]Let's clear the relationship Recovery model and In-Memory Table

Recovery model選項,可以控制交易的紀錄方式,以及可用的還原交易類型,

大家也一定都知道,Simple將使用最少交易紀錄,Full使用最多交易紀錄,

但對In-Memory table 是否有ㄧ樣的關聯呢 ?

最近我在整理一個系統,我打算使用In-Memory特性來改善latency,

我觀察In-Memory table for DML的交易紀錄使用量,就算我使用Simple也無法更降低使用量(基本上和FULL沒有兩樣),

我後來想想SQL Server這樣處理是正確的,如果它不完整記錄In-Memory table for DML,

那麼它又該如何確保復原所有資料,下面我簡單驗證資料庫復原選項,和In-Memory table for DML真的完全沒有任何關聯。

Note: In-Memory table交易紀錄檔使用量,遠遠低於disk table使用量。

--Full
alter database mymemoryDB set recovery full with no_wait
select name,recovery_model,recovery_model_desc 
from sys.databases
where [name]=N'mymemoryDB'
dbcc sqlperf ('LOGSPACE');

Log space used(%):2.41

--insert data
set nocount on
declare @i int=0
while(@i<10000)
begin
 insert into [dbo].[myorders] values(@i,N'I am Rico',GETDATE())
 set @i+=1
end

Log space used(%):5.42,成長約3%

--select number of log and total size
SELECT sum(f.[Log Record Length]),count(*)
FROM fn_dblog_xtp(NULL,NULL) AS f
INNER JOIN sys.memory_optimized_tables_internal_attributes m
ON (f.xtp_object_id - 2147483648) = (m.xtp_object_id + 2147483648) 
WHERE m.[object_id] =object_id('dbo.myorders')
and operation_desc=N'HK_LOP_INSERT_ROW'

完整記錄1000筆,總共大小: 1360000。

 

--Simple
alter database mymemoryDB set recovery simple with no_wait
dbcc sqlperf ('LOGSPACE'); --82.86528
go

Log space used(%):5.16

--insert data
set nocount on
declare @i int=0
while(@i<10000)
begin
 insert into [dbo].[myorders] values(@i,N'I am Rico',GETDATE())
 set @i+=1
end

Log space used(%):8.16,成長約3%

--select number of log and total size

完整記錄1000筆,總共大小: 1360000,和完整復原模式一模一樣。

 

參考

New SQL Server 2014 Dynamic Management Views

How Hekaton (XTP) achieves Durability for “Memory Optimised” Tables

Identifying In-Memory Objects When Querying the Transaction Log

In-Memory OLTP in SQL Server: Logging Comparison with Disk-Based Tables