Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to Query Extent Information


How to Query Extent Information

Author
Message
amoericke
amoericke
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 243
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.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)

Group: General Forum Members
Points: 57111 Visits: 44707
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

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


amoericke
amoericke
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 243
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).
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search