- IN_ROW_DATA (btree and heap) allocation unit
- LOB_DATA allocation unit
- ROW_OVERFLOW_DATA allocation unit
USE mydb
GOCREATE TABLE IAMTable(
Id INT,
data1 VARCHAR(3000),
data2 VARCHAR(3000),
data3 VARCHAR(3000),
Lobdata NTEXT)GO
Now let us insert a record into this table
INSERT INTO IAMTable VALUES (1,'A','B','C',N'Test')
Here we are inserting a record which will not generate row overflow. We will use the DBCC IND command to list the pages allocated to this table.
DBCC IND('mydb','IAMTable',1)
Fig 1 |
DECLARE @data1 VARCHAR(3000)
SET @data1 = REPLICATE('A',3000)
INSERT INTO IAMTable VALUES (1,@data1,@data1,@data1,N'Test')
GO
DBCC IND('mydb','IAMTable',1)
Fig 2 |
Now the table has IAM pages for all three allocation units. If we have more partition on this table, there will be separate set of IAM pages for each partition. Below picture will give you a pictorial representation.
In short a heap/B tree structure can have minimum of one IAM page and maximum of (No. of partition X 3) IAM pages. If the tables grows further and pages allocated from different GAM interval, more IAM pages will be added.These IAM pages need to be linked together and this list is called IAM chain.
DBCC traceon(3604)
GO
DBCC page('mydb',1,126,3)
In the IAM header section , we can see following field.
- SequenceNumber : This is the position of the IAM page in the IAM chain. This increases by one for each page added to the IAM chain.
- Status: Unused
- Objectid : Unused
- Indexid : Unused
- Page_Count : Unused
- Start_pg:This is the GAM interval that the page maps.It store the first page id in the mapped GAM interval.
This part has referenced from : http://www.sqlskills.com/blogs/paul/inside-the-storage-engine-iam-pages-iam-chains-and-allocation-units/
Let us execute the below script 7 time . After that there will be 9 records in the table (Two records are inserted as part of earlier step)
SET @data1 = REPLICATE('A',3000)
INSERT INTO IAMTable VALUES (1,@data1,@data1,@data1,N'Test')
Now let us see how the IAM page looks like
DBCC traceon(3604)
GO
DBCC page('mydb',1,126,3)
All single page allocation are done and for the 9th record, SQL server allocated an extent which start from page no 192 to 199.
Note : I have learned a lot about internals from Paul S Randal blog . This is only an attempt to represent the way I understood.
If you liked this post, do like my page on FaceBook