December 21, 2009 at 9:53 am
I’m trying to see which extents my pages are on, or put another way, which pages make up each extent. I’ve been using sys.fn_PhysLocFormatter (%%physloc%%) to see which page each row in a table is on, but I’d also like to know which pages belong to which extents. For example, if I have a table with 500 rows and I view each row and which page it’s on, I’d like to know which pages make up an extent.
Does anyone know of a way to do this? The only way I can think of would be to somehow view the IAM pages, and then do some sort of painful translation to figure it out.
December 21, 2009 at 10:34 am
An extent is a contiguous 8 pages. So, given that the first page in the database is page 0, the first extent is made up of pages 0..7. The second of 8..15, etc.
Hence, while extents aren't actually numbered within a database (pages are), one could say that an arbitrary extent 'n' consists of the 8 pages from (n-1)*8..(n*8)-1.
Make sense?
I'm curious though. Why are you interested?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 21, 2009 at 10:57 am
It's related to my post "How Does SQL Reuse Data Pages?", which you replied to as well. When a new row is inserted, SQL uses the IAM page to find an extent with free space. So, in trying to figure out how SQL determines where a new row will get inserted, I believe I'd need to know extent information along with the page information returned by sys.fn_PhysLocFormatter. In my testing, it seemed odd the way SQL would go back and reuse an "old" page. My accurately, it seemed odd "when" SQL would decide to go back and reuse an "old" page. I think I need to take into account extents to make some sense of it all, and not simply look at the pages.
From "Managing Space Used by Objects" in Books Online;
When the 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 Database Engine uses the IAM pages to find the extents allocated to the allocation unit. For each extent, the 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.
I think I need to look at when an entire extent has become full, and then see where SQL starts inserting the new rows, keeping in mind that SQL looks for free space by searching extents, not simply by searching pages.
Thanks again for your input. I think I can modify my SELECT statement to return an integer representing the extent each page belongs to (simply meant to help me "group" pages together).
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply