{"id":1067,"date":"2008-03-20T00:25:13","date_gmt":"2008-03-20T00:25:13","guid":{"rendered":"\/blogs\/paul\/post\/SQL-Server-2008-New-(undocumented)-physical-row-locator-function.aspx"},"modified":"2008-03-20T00:25:13","modified_gmt":"2008-03-20T00:25:13","slug":"sql-server-2008-new-undocumented-physical-row-locator-function","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/","title":{"rendered":"SQL Server 2008: New (undocumented) physical row locator function"},"content":{"rendered":"<p><FONT face=Verdana size=2><br \/>\n<P>One of the drawbacks of not being in the SQL team at Microsoft any longer is that I don&#8217;t know about all the undocumented features in the next release &#8211; I have to hunt around for them like everyone else :-(<\/P><br \/>\n<P>So I was poking about in SSMS&nbsp;in 2008 CTP-6 and noticed a function called&nbsp;<EM><STRONG>sys.fn_PhysLocCracker<\/STRONG><\/EM> that I&#8217;d never heard of. Doing an <FONT face=\"Courier New\">sp_helptext <\/FONT>on it gets the following output:<\/P><br \/>\n<BLOCKQUOTE dir=ltr style=\"MARGIN-RIGHT: 0px\"><br \/>\n<P><FONT face=\"Courier New\">&#8212; Name: sys.fn_PhysLocCracker <BR>&#8212;<BR>&#8212; Description:<BR>&#8212;&nbsp;Cracks the output of %%physloc%% virtual column<BR>&#8212;<BR>&#8212; Notes:<BR>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<BR>create function sys.fn_PhysLocCracker (@physical_locator binary (8))<BR>returns @dumploc_table table<BR>(<BR>&nbsp;[file_id]&nbsp;int not null,<BR>&nbsp;[page_id]&nbsp;int not null,<BR>&nbsp;[slot_id]&nbsp;int not null<BR>)<BR>as<BR>begin<\/FONT><\/P><br \/>\n<P><FONT face=\"Courier New\">&nbsp;declare @page_id&nbsp;binary (4)<BR>&nbsp;declare @file_id&nbsp;binary (2)<BR>&nbsp;declare @slot_id&nbsp;binary (2)<\/FONT><\/P><br \/>\n<P><FONT face=\"Courier New\">&nbsp;&#8212; Page ID is the first four bytes, then 2 bytes of page ID, then 2 bytes of slot<BR>&nbsp;&#8212;<BR>&nbsp;select @page_id = convert (binary (4), reverse (substring (@physical_locator, 1, 4)))<BR>&nbsp;select @file_id = convert (binary (2), reverse (substring (@physical_locator, 5, 2)))<BR>&nbsp;select @slot_id = convert (binary (2), reverse (substring (@physical_locator, 7, 2)))<BR>&nbsp;<BR>&nbsp;insert into @dumploc_table values (@file_id, @page_id, @slot_id)<BR>&nbsp;return<BR>end<\/FONT><\/P><\/BLOCKQUOTE><br \/>\n<P>Cool &#8211; but something else I&#8217;ve never heard of <STRONG><EM>%%physloc%%<\/EM><\/STRONG> &#8211; what&#8217;s that? After playing around for a while, I figured out how to make it work.&nbsp; Just to be confusing, there&#8217;s another identical version of the function called <STRONG><EM>sys.fn_PhysLocFormatter<\/EM><\/STRONG> &#8211; and that&#8217;s the only one I could get to work. Here&#8217;s an example:<\/P><br \/>\n<BLOCKQUOTE dir=ltr style=\"MARGIN-RIGHT: 0px\"><br \/>\n<P><FONT face=\"Courier New\"><FONT color=#0000ff>CREATE TABLE<\/FONT> TEST <FONT color=#808080>(<\/FONT>c1 <FONT color=#0000ff>INT IDENTITY<\/FONT><FONT color=#808080>,<\/FONT> c2 <FONT color=#0000ff>CHAR<\/FONT> <FONT color=#808080>(<\/FONT>4000<FONT color=#808080>)<\/FONT> <FONT color=#0000ff>DEFAULT<\/FONT> <FONT color=#ff0000>&#8216;a&#8217;<\/FONT><\/FONT><FONT face=\"Courier New\"><FONT color=#808080>);<BR><\/FONT><FONT color=#0000ff>GO<\/FONT><BR><FONT color=#0000ff>INSERT INTO<\/FONT> TEST <FONT color=#0000ff>DEFAULT VALUES<\/FONT><\/FONT><FONT face=\"Courier New\"><FONT color=#808080>;<BR><\/FONT><FONT color=#0000ff>INSERT INTO<\/FONT> TEST <FONT color=#0000ff>DEFAULT VALUES<\/FONT><\/FONT><FONT face=\"Courier New\"><FONT color=#808080>;<BR><\/FONT><FONT color=#0000ff>INSERT INTO<\/FONT> TEST <FONT color=#0000ff>DEFAULT VALUES<\/FONT><FONT color=#808080>;<\/FONT><BR><FONT color=#0000ff>GO<\/FONT><\/FONT><\/P><br \/>\n<P><FONT face=\"Courier New\">SELECT <FONT color=#006400>sys<\/FONT><FONT color=#808080>.<\/FONT>fn_PhysLocFormatter <FONT color=#808080>(%%<\/FONT>physloc<FONT color=#808080>%%) <FONT color=#0000ff>AS<\/FONT> <FONT color=#000000>[Physical RID]<\/FONT>, *<\/FONT> FROM TEST<FONT color=#808080>;<\/FONT><BR><FONT color=#0000ff>GO<\/FONT><\/FONT><\/P><br \/>\n<P dir=ltr><FONT face=\"Courier New\">Physical RID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c1<BR>&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&nbsp; &#8212;&#8212;&#8212;&#8211;<BR>(1:411:0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1<BR>(1:411:1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2<BR>(1:413:0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3<\/FONT><\/P><FONT face=\"Courier New\"><\/FONT><\/BLOCKQUOTE><br \/>\n<P><FONT face=\"Courier New\"><FONT face=Verdana>It&#8217;s a physical-record locator function! Undocumented and unsupported (obviously), but hey, some of the best features are :-) It gives the database file, page within the file, and slot number on the page in the format (file:page:slot). I can think of a *bunch* of uses for this which I&#8217;ll be exploring over the next few months.<\/FONT><\/FONT><\/P><br \/>\n<P><FONT face=\"Courier New\"><FONT face=Verdana>How cool is that?!?!<\/FONT><\/FONT><\/P><\/FONT><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the drawbacks of not being in the SQL team at Microsoft any longer is that I don&#8217;t know about all the undocumented features in the next release &#8211; I have to hunt around for them like everyone else :-( So I was poking about in SSMS&nbsp;in 2008 CTP-6 and noticed a function called&nbsp;sys.fn_PhysLocCracker [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,62,86,100],"tags":[],"class_list":["post-1067","post","type-post","status-publish","format-standard","hentry","category-inside-the-storage-engine","category-on-disk-structures","category-sql-server-2008","category-undocumented-commands"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Server 2008: New (undocumented) physical row locator function - Paul S. Randal<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server 2008: New (undocumented) physical row locator function - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"One of the drawbacks of not being in the SQL team at Microsoft any longer is that I don&#8217;t know about all the undocumented features in the next release &#8211; I have to hunt around for them like everyone else :-( So I was poking about in SSMS&nbsp;in 2008 CTP-6 and noticed a function called&nbsp;sys.fn_PhysLocCracker [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2008-03-20T00:25:13+00:00\" \/>\n<meta name=\"author\" content=\"Paul Randal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Randal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/\",\"name\":\"SQL Server 2008: New (undocumented) physical row locator function - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"datePublished\":\"2008-03-20T00:25:13+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server 2008: New (undocumented) physical row locator function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\",\"name\":\"Paul S. Randal\",\"description\":\"In Recovery...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\",\"name\":\"Paul Randal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"caption\":\"Paul Randal\"},\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/paul\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Server 2008: New (undocumented) physical row locator function - Paul S. Randal","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server 2008: New (undocumented) physical row locator function - Paul S. Randal","og_description":"One of the drawbacks of not being in the SQL team at Microsoft any longer is that I don&#8217;t know about all the undocumented features in the next release &#8211; I have to hunt around for them like everyone else :-( So I was poking about in SSMS&nbsp;in 2008 CTP-6 and noticed a function called&nbsp;sys.fn_PhysLocCracker [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/","og_site_name":"Paul S. Randal","article_published_time":"2008-03-20T00:25:13+00:00","author":"Paul Randal","twitter_misc":{"Written by":"Paul Randal","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/","name":"SQL Server 2008: New (undocumented) physical row locator function - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"datePublished":"2008-03-20T00:25:13+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/sql-server-2008-new-undocumented-physical-row-locator-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"SQL Server 2008: New (undocumented) physical row locator function"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/","name":"Paul S. Randal","description":"In Recovery...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce","name":"Paul Randal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","caption":"Paul Randal"},"sameAs":["http:\/\/3.209.169.194\/blogs\/paul"],"url":"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/1067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/comments?post=1067"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/1067\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=1067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=1067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=1067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}