Tuesday, September 26, 2017

SQL Server - formerly dirty data page still in bpool after checkpoint?

@Kevin3NF asked the question, and @NedOtter added the important clarification that my answer is for the context of on-disk rowstore, since Hekaton tables are outside of the bpool thus bpool dirty pages don't apply.

*****

A question came up on Twitter #\sqlhelp that caught my eye today.

Paraphrasing: After a checkpoint writes a dirty database page, does that page remain in the buffer pool as a clean page?

I thought the answer was yes, but figured I better check :-)

My test code...

SELECT @@version AS sqlServer_version;
DROP TABLE IF EXISTS sasq_Test_checkpoint;
SELECT convert(int, 1) num INTO sasq_Test_checkpoint;

SELECT db_name(bd.database_id) dbName, bd.file_id, object_name(sp.object_id) o_name, bd.page_id, bd.page_level, bd.page_type, au.[type_desc], bd.is_modified 
FROM sys.dm_os_buffer_descriptors bd
JOIN sys.allocation_units au ON bd.allocation_unit_id = au.allocation_unit_id 
JOIN sys.partitions sp ON au.container_id = CASE WHEN au.[type_desc] IN ('IN_ROW_DATA', 'ROW_OVERFLOW_DATA') THEN sp.hobt_id ELSE sp.partition_id END
WHERE bd.database_id = db_id()
AND sp.object_id = object_id('sasq_Test_checkpoint'); 

CHECKPOINT;

SELECT db_name(bd.database_id) dbName, bd.file_id, object_name(sp.object_id) o_name, bd.page_id, bd.page_level, bd.page_type, au.[type_desc], bd.is_modified 
FROM sys.dm_os_buffer_descriptors bd
JOIN sys.allocation_units au ON bd.allocation_unit_id = au.allocation_unit_id 
JOIN sys.partitions sp ON au.container_id = CASE WHEN au.[type_desc] IN ('IN_ROW_DATA', 'ROW_OVERFLOW_DATA') THEN sp.hobt_id ELSE sp.partition_id END
WHERE bd.database_id = db_id()
AND sp.object_id = object_id('sasq_Test_checkpoint');


And... the results...

Good, I got that one right :-)

Ciao for now!

No comments:

Post a Comment