SQL Server中頁與SQL Server盤區
以下的文章主要是對SQL Server中頁與SQL Server盤區的正確理解,在SQL Server數據庫中其最基本的存儲單元是頁(page)。系統給數據庫文件(.mdf .ndf)分配的磁盤空間邏輯上被分解為從0..n的多個編號連續的頁。
磁盤的I/O操作是在頁級水平完成的,也就是說,SQL Server每次讀或寫整個的數據頁(data page).
盤區(Extent)是物理上連續的8個頁,這樣便于有效地管理頁,所有的頁都存儲在SQL Server盤區。
頁(Pages)
在SQL Server中,頁的大小為8KB。這意味著1M字節可以有128頁。每頁有一個96字節的頁頭(Header),頁頭用來存儲頁的系統信息,具體包括:頁編號,頁類型、該頁剩余空閑空間、
下面表列出了SQL Server的數據文件中所用的頁的類型
- page Type contents
- Data Data rows with all data, except text, ntext, image, nvarchar(max), varchar(max), varbinary(max), and xml data, when text in row is set to ON.
- Index Index entries.
- Text/Image Large object data types: * text, ntext, image, nvarchar(max), varchar(max), varbinary(max),
- and xml dataVariable length columns when the data row exceeds 8 KB: * varchar, nvarchar, varbinary, and sql_variant
- Global Allocation Map, Shared Global Allocation Map Information about whether extents are allocated.
- Page Free Space Information about page allocation and free space available on pages.
- Index Allocation Map Information about extents used by a table or index per allocation unit.
- Bulk Changed Map Information about extents modified by bulk operations since the last BACKUP LOG statement per allocation unit.
- Differential Changed Map Information about extents that have changed since the last BACKUP DATABASE statement per allocation unit.
數據行在頁頭之后,按順序存儲在頁中。在頁的底部有一個記錄每行偏移量的表格,這個偏移量表格的每行對應于頁中的每行記錄。每個偏移量用來表示每行記錄的***個字節與頁開始的
位置的距離。偏移量表格中行與頁中行的順序相反。
盤區(Extents)
盤區是管理磁盤空間的基本單元。每個SQL Server盤區是由物理上連續的8個頁構成,也就是說,每兆磁盤空間可以容納16個盤區。
為了更有效分配空間,SQL Server不為小數據量的表分配一個完整的盤區。SQL Server有兩種類型盤區:
uniform extents:由一個對象擁有,該盤區中8個頁只能有擁有者來使用
Mixed extents:可以由8個對象擁有,8個頁可以由不同對象使用。
一個新表或索引通常是從混合SQL Server盤區中分配頁,當表或索引的大小增長超過了8頁,那么就以uniform extents方式進行分配。當在已存在的表上創建索引,如果表中行對應的索引大小超過了8頁,也以uniform extents方式分配空間。
上述的相關內容就是對理解SQL Server中頁和SQL Server盤區的描述,希望會給你帶來一些幫助在此方面。
【編輯推薦】