SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Get Object Name from database_id, file_id, Page_id


Get Object Name from database_id, file_id, Page_id

Author
Message
EdVassie
EdVassie
SSCertifiable
SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)

Group: General Forum Members
Points: 5968 Visits: 3866
I have Buffer Pool Extension enabled and want to get the object name for all pages shown in sys.dm_os_buffer_descriptors.

When a page is in the BPE and no longer in the Bufferpool, the normal way of working this out via allocation_unit_id cannot be used as that column is null as shown below.



Does anyone know a SQL query that can get to the object_id using just the database_id, file_id and page_id WITHOUT using DBCC PAGE. I need to get a result set that includes the object_id for every row in sys.dm_os_buffer_descriptors.

Original author: SQL Server FineBuild 1-click install and best practice configuration of SQL Server 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005. 14 Mar 2017: now over 40,000 downloads.Disclaimer: All information provided is a personal opinion that may not match reality.Quote: When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist. - Archbishop Hélder Câmara
sqlbuddy123
sqlbuddy123
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2436 Visits: 2243
EdVassie (3/5/2014)
I have Buffer Pool Extension enabled and want to get the object name for all pages shown in sys.dm_os_buffer_descriptors.

When a page is in the BPE and no longer in the Bufferpool, the normal way of working this out via allocation_unit_id cannot be used as that column is null as shown below.



Does anyone know a SQL query that can get to the object_id using just the database_id, file_id and page_id WITHOUT using DBCC PAGE. I need to get a result set that includes the object_id for every row in sys.dm_os_buffer_descriptors.



Check this one ..

SELECT *, OBJ.name AS Object_Name
FROM sys.dm_os_buffer_descriptors AS bd
INNER JOIN
(
SELECT object_name(object_id) AS name
,index_id ,allocation_unit_id
FROM sys.allocation_units AS au
INNER JOIN sys.partitions AS p
ON au.container_id = p.hobt_id
AND (au.type = 1 OR au.type = 3)
UNION ALL
SELECT object_name(object_id) AS name
,index_id, allocation_unit_id
FROM sys.allocation_units AS au
INNER JOIN sys.partitions AS p
ON au.container_id = p.partition_id
AND au.type = 2
) AS obj
ON bd.allocation_unit_id = obj.allocation_unit_id
--WHERE database_id = db_id()



--
SQLBuddy
GilaMonster
GilaMonster
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89839 Visits: 45284
Potentially. I haven't tried this because I don't have a 2012 instance available. It's undocumented.

SELECT * 
FROM sys.dm_db_database_page_allocations(DB_ID('<Database Name>'), NULL, NULL, NULL, 'DETAILED') dpa
WHERE allocated_page_file_id = @FileID AND allocated_page_page_id = @PageID



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


GilaMonster
GilaMonster
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89839 Visits: 45284
sqlbuddy123 (3/5/2014)
Check this one ..

SELECT *, OBJ.name AS Object_Name
FROM sys.dm_os_buffer_descriptors AS bd
INNER JOIN
(
SELECT object_name(object_id) AS name
,index_id ,allocation_unit_id
FROM sys.allocation_units AS au
INNER JOIN sys.partitions AS p
ON au.container_id = p.hobt_id
AND (au.type = 1 OR au.type = 3)
UNION ALL
SELECT object_name(object_id) AS name
,index_id, allocation_unit_id
FROM sys.allocation_units AS au
INNER JOIN sys.partitions AS p
ON au.container_id = p.partition_id
AND au.type = 2
) AS obj
ON bd.allocation_unit_id = obj.allocation_unit_id
--WHERE database_id = db_id()



How would that work when the allocation_unit_id is null, as shown in the image and as Ed explicitly stated?

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


SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33226 Visits: 18560
GilaMonster (3/5/2014)
Potentially. I haven't tried this because I don't have a 2012 instance available. It's undocumented.

SELECT * 
FROM sys.dm_db_database_page_allocations(DB_ID('<Database Name>'), NULL, NULL, NULL, 'DETAILED') dpa
WHERE allocated_page_file_id = @FileID AND allocated_page_page_id = @PageID



Should work. I might add database_id to the predicate.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

GilaMonster
GilaMonster
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89839 Visits: 45284
SQLRNNR (3/5/2014)
GilaMonster (3/5/2014)
Potentially. I haven't tried this because I don't have a 2012 instance available. It's undocumented.

SELECT * 
FROM sys.dm_db_database_page_allocations(DB_ID('<Database Name>'), NULL, NULL, NULL, 'DETAILED') dpa
WHERE allocated_page_file_id = @FileID AND allocated_page_page_id = @PageID



Should work. I might add database_id to the predicate.


No need, because the first parameter to the function limits the returned resultset to just the DB of interest. It's like index_physical_stats.

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


SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33226 Visits: 18560
GilaMonster (3/5/2014)
SQLRNNR (3/5/2014)
GilaMonster (3/5/2014)
Potentially. I haven't tried this because I don't have a 2012 instance available. It's undocumented.

SELECT * 
FROM sys.dm_db_database_page_allocations(DB_ID('<Database Name>'), NULL, NULL, NULL, 'DETAILED') dpa
WHERE allocated_page_file_id = @FileID AND allocated_page_page_id = @PageID



Should work. I might add database_id to the predicate.


No need, because the first parameter to the function limits the returned resultset to just the DB of interest. It's like index_physical_stats.


Fair point. I ran it and passed the DBName to the parameter. So, dunno what I was thinking.Whistling



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

EdVassie
EdVassie
SSCertifiable
SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)

Group: General Forum Members
Points: 5968 Visits: 3866
Gail's code looks like it might work :-)

I am out of office until Monday 10 and will check it out then. Thanks for the suggestion!

BTW, Buffer Pool Extension is a really good addition to SQL Server. We put a 400GB BPE file on to our 60GB BI server and when I last checked we were getting about 70% hit rate on the BPE, and a lot more throughput on user reporting. IMHO anyone considering SQL2014 backed by spinning disks should aim to get SSD space and exploit the BPE.

Original author: SQL Server FineBuild 1-click install and best practice configuration of SQL Server 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005. 14 Mar 2017: now over 40,000 downloads.Disclaimer: All information provided is a personal opinion that may not match reality.Quote: When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist. - Archbishop Hélder Câmara
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