Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to Query Extent Information Expand / Collapse
Author
Message
Posted Monday, December 21, 2009 9:53 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, February 07, 2014 10:31 AM
Points: 38, Visits: 214
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.
Post #837340
Posted Monday, December 21, 2009 10:34 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 11:52 AM
Points: 41,530, Visits: 34,446
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #837374
Posted Monday, December 21, 2009 10:57 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, February 07, 2014 10:31 AM
Points: 38, Visits: 214
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).

Post #837392
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse