Site icon TheWindowsUpdate.com

SQL Server IAM page

This post has been republished via RSS; it originally appeared at: SQL Server Support articles.

Hi Guys, welcome to SQL Server Allocation Series, hope you enjoy the post1 and post2.

Today, I’m going to show you the detail of IAM page.

An Index Allocation Map (IAM) page maps the extents in a 4-GB part of a database file used by an allocation unit. An allocation unit is one of three types:

Each partition of a heap or index contains at least an IN_ROW_DATA allocation unit. It may also contain a LOB_DATA or ROW_OVERFLOW_DATA allocation unit, depending on the heap or index schema.

An IAM page covers a 4-GB range in a file and is the same coverage as a GAM or SGAM page. If the allocation unit contains extents from more than one file, or more than one 4-GB range of a file, there will be multiple IAM pages linked in an IAM chain. Therefore, each allocation unit has at least one IAM page for each file on which it has extents. There may also be more than one IAM page on a file, if the range of the extents on the file allocated to the allocation unit exceeds the range that a single IAM page can record.

 

 

IAM pages linked in a chain per allocation unit An IAM page has a header that indicates the starting extent of the range of extents mapped by the IAM page. The IAM page also has a large bitmap in which each bit represents one extent. The first bit in the map represents the first extent in the range, the second bit represents the second extent, and so on. If a bit is 0, the extent it represents is not allocated to the allocation unit owning the IAM. If the bit is 1, the extent it represents is allocated to the allocation unit owning the IAM page.

When the SQL Server Database Engine has to insert a new row and no space is available in the current page, it uses the IAM and PFS pages to find a page to allocate, or, for a heap or a Text/Image page, a page with sufficient space to hold the row. The SQL Server Database Engine uses the IAM pages to find the extents allocated to the allocation unit. For each extent, the SQL Server Database Engine searches the PFS pages to see if there is a page that can be used. Each IAM and PFS page covers lots of data pages, so there are few IAM and PFS pages in a database. This means that the IAM and PFS pages are generally in memory in the SQL Server buffer pool, so they can be searched quickly. For indexes, the insertion point of a new row is set by the index key, but when a new page is needed, the previously described process occurs.

 

 

In post 1, I created a table with 8 pages, all these 8 pages are in mixed extent. I’m going to insert more rows into the table to increase the pages. As you expected, these new rows/pages will be allocated to uniform extents.

I’m going to walk you through how SQL Server save the info in IAM pages.

Data manipulation:

T-SQL:

insert heaptable1 values(15,REPLICATE('o',8000))     --page 9

insert heaptable1 values(16,REPLICATE('p',8000))     --page 10

insert heaptable1 values(17,REPLICATE('q',8000))     --page 11

insert heaptable1 values(18,REPLICATE('r',8000))     --page 12

insert heaptable1 values(19,REPLICATE('s',8000))     --page 13

insert heaptable1 values(20,REPLICATE('t',8000))     --page 14

insert heaptable1 values(21,REPLICATE('u',8000))     --page 15

insert heaptable1 values(22,REPLICATE('v',8000))     --page 16

insert heaptable1 values(23,REPLICATE('w',8000))     --page 17

 

The table heaptable1 has 17 pages in four extents, two mixed extents and two uniform extents.

select allocated_page_file_id as [FileID],allocated_page_page_id as [PageID],page_type_desc,extent_page_id/8 as ExtentID,

is_mixed_page_allocation,extent_page_id as [First Page in Extent],extent_page_id+7 as [LastPage in Extent],is_allocated From 

sys.dm_db_database_page_allocations(db_id(),object_id('dbo.heaptable1'),null,null,'detailed')  order by allocated_page_page_id

 

Page 246 is the IAM page.

Page 245,247,328,329,330,331,332 and 333 are in mixed extent.

Starting from page (1:352), all the pages are allocated in uniform extent.

Page(1:352)~(1:359) are in extent 44,

Page(1:360)~(1:367) are in extent 45.

 

Let me run DBCC PAGE of IAM page to show you how the info recorded.

 

The first 8 pages are listed under ‘Single page allocations’, which means they are in mixed extent.

(1:352)~(1:360) are in uniform extent, the result matches the DMF sys.dm_db_database_page_allocations

(1:352) is the first page of extent 44

(1:360) is the first page of extent 45

 

Let’s dive deep into the IAM page with parameter 1:

 

 

1.There are two slots in IAM page,

2.Let me interpret the slot 0.

1)Each string in rectangle stands for one page, the format is PageId:FileId.

2)The first 8 characters are page id, the last four part is for Fileid.

Here is the interpretation table:

Original string->

PId:FileId->

FId:PId->

FId:PId->

FId:PId(Decimal)

f50000000100

f5000000:0100

0100: f5000000

0001:000000f5

1:245

f70000000100

f7000000:0100

0100:f7000000

0001:000000f7

1:247

480100000100

48010000:0100

0100:48010000

0001:00000148

1:328

490100000100

49010000:0100

0100:49010000

0001:00000149

1:329

4a0100000100

4a010000:0100

0100:4a010000

0001:0000014a

1:330

4b0100000100

4b010000:0100

0100:4b010000

0001:0000014b

1:331

4c0100000100

4c010000:0100

0100:4c010000

0001:0000014c

1:332

4d0100000100

4d010000:0100

0100:4d010000

0001:0000014d

1:333

3.I have demonstrate how the IAM page stores the first 8 pages in mixed extent, now let’s move on to the uniform extent.

 

4.The uniform extents info is stored in the second slot(slot 1).

 

 

1)’0000381f’ is reserved, we don’t need to worry about it.

2)The string I cared about is ‘00000000 0030’

Following table interprets the string.

 

3)Each bit in the table stands for one extent.

4)0 means the extent is not occupied/allocated by this table of the IAM.

5)1 means the extent is occupied/allocated by this table of IAM, and it’s uniform extent.

6)Here is more detail

 

Which exactly as same as the result we got from DBCC Page with parameter 3 before.

 

 

You may download the dbtest20200904.zip and give it a try.

Exit mobile version