{"id":4998,"date":"2019-06-11T13:07:11","date_gmt":"2019-06-11T20:07:11","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/paul\/?p=4998"},"modified":"2019-06-11T13:08:08","modified_gmt":"2019-06-11T20:08:08","slug":"the-curious-case-of-how-to-find-which-page-an-index-row-is-on","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/","title":{"rendered":"The Curious Case of\u2026 how to find which page an index row is on"},"content":{"rendered":"<p style=\"text-align: justify;\"><em>(The Curious Case of\u2026<\/em>\u00a0used to be part of our bi-weekly\u00a0<a href=\"https:\/\/www.sqlskills.com\/join-the-sqlskills-insider-community\/\" target=\"_blank\" rel=\"noopener noreferrer\">newsletter<\/a>\u00a0but we decided to make it a\u00a0regular blog post instead so it can sometimes be more frequent. It covers something interesting one of us encountered when working with a client, doing some testing, or were asked in a random question from the community.)<\/p>\n<p style=\"text-align: justify;\">I was working recently on a client&#8217;s corruption issue where I needed to know how to find which page an index row is on. The client was getting\u00a0weird errors from <em>DBCC CHECKDB<\/em> around missing nonclustered index records, but <em>SELECT<\/em>s using that index on the supposedly missing key values would work. I suspected a stale read problem from the I\/O subsystem as part of building the database snapshot that <em>DBCC CHECKDB<\/em> uses, but needed to prove which page the issue was on.<\/p>\n<p style=\"text-align: justify;\">There&#8217;s a cool undocumented column that you can select called <em>%%PHYSLOC%%<\/em> that gives the page:record:slot of the selected record, and I&#8217;ve used it many times when working on corruption\/data recovery issues for clients. It gives the information back in hex, so there&#8217;s a companion function called\u00a0<em>sys.fn_PhysLocCracker<\/em> that formats the output nicely. Both of these have been in the product since SQL Server 2005.<\/p>\n<p style=\"text-align: justify;\">Let me show you an example using the old\u00a0<em>AdventureWorks<\/em> sample database.<\/p>\n<p style=\"text-align: justify;\">Let&#8217;s say there&#8217;s a corruption issue where it says there&#8217;s a missing row for\u00a0<em>StateProvinceID = 1<\/em> and <em>AddressID = 519<\/em> in the\u00a0<em>IX_Address_StateProvinceID<\/em> nonclustered index (which is index ID 4) of the <em>Person.Address<\/em> table. If I want to prove that that row is NOT missing, here&#8217;s what I can do:<\/p>\n<pre class=\"brush: sql; title: ; toolbar: true; wrap-lines: true; notranslate\" title=\"\">\r\nSELECT\r\n\t&#x5B;StateProvinceID]\r\n\t, &#x5B;AddressID]\r\n\t, &#x5B;physloc].*\r\nFROM &#x5B;Person].&#x5B;Address]\r\nWITH (INDEX = 4)\r\nCROSS APPLY sys.fn_PhysLocCracker (%%physloc%%) AS &#x5B;physloc]\r\nWHERE &#x5B;StateProvinceID] = 1\r\n\tAND &#x5B;AddressID] = 519;\r\nGO\r\n<\/pre>\n<p style=\"text-align: justify;\">I&#8217;m selecting the index keys for the nonclustered index and using an index hint to force that index to be used.<\/p>\n<p style=\"text-align: justify;\">And if I get any output, the row exists. In this case, I get:<\/p>\n<pre class=\"brush: plain; gutter: false; title: ; toolbar: true; wrap-lines: true; notranslate\" title=\"\">\r\nStateProvinceID AddressID   file_id     page_id     slot_id\r\n--------------- ----------- ----------- ----------- -----------\r\n1               519         1           8120        9\r\n<\/pre>\n<p>Pretty cool!<\/p>\n<p>I&#8217;ve also used this to find rows that I need to bit-twiddle using <a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/dbcc-writepage\/\" target=\"_blank\" rel=\"noopener noreferrer\"><em>DBCC WRITEPAGE<\/em><\/a> to work around corruptions to allow data recovery from trashed databases &#8211; tedious, but possible if you know what you&#8217;re doing.<\/p>\n<p style=\"text-align: justify;\">Bottom line:\u00a0there are quite a few little undocumented columns and functions you can use to easily get internals information about SQL Server, with real-world applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(The Curious Case of\u2026\u00a0used to be part of our bi-weekly\u00a0newsletter\u00a0but we decided to make it a\u00a0regular blog post instead so it can sometimes be more frequent. It covers something interesting one of us encountered when working with a client, doing some testing, or were asked in a random question from the community.) I was working [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,115],"tags":[],"class_list":["post-4998","post","type-post","status-publish","format-standard","hentry","category-corruption","category-the-curious-case-of"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>The Curious Case of\u2026 how to find which page an index row is on - Paul S. Randal<\/title>\n<meta name=\"description\" content=\"The Curious Case of\u2026 how to find which page an index row is on\" \/>\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\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Curious Case of\u2026 how to find which page an index row is on - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"The Curious Case of\u2026 how to find which page an index row is on\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2019-06-11T20:07:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-06-11T20:08:08+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\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/\",\"name\":\"The Curious Case of\u2026 how to find which page an index row is on - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"datePublished\":\"2019-06-11T20:07:11+00:00\",\"dateModified\":\"2019-06-11T20:08:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"description\":\"The Curious Case of\u2026 how to find which page an index row is on\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Curious Case of\u2026 how to find which page an index row is on\"}]},{\"@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":"The Curious Case of\u2026 how to find which page an index row is on - Paul S. Randal","description":"The Curious Case of\u2026 how to find which page an index row is on","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\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/","og_locale":"en_US","og_type":"article","og_title":"The Curious Case of\u2026 how to find which page an index row is on - Paul S. Randal","og_description":"The Curious Case of\u2026 how to find which page an index row is on","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/","og_site_name":"Paul S. Randal","article_published_time":"2019-06-11T20:07:11+00:00","article_modified_time":"2019-06-11T20:08:08+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\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/","name":"The Curious Case of\u2026 how to find which page an index row is on - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"datePublished":"2019-06-11T20:07:11+00:00","dateModified":"2019-06-11T20:08:08+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"description":"The Curious Case of\u2026 how to find which page an index row is on","breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/the-curious-case-of-how-to-find-which-page-an-index-row-is-on\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"The Curious Case of\u2026 how to find which page an index row is on"}]},{"@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\/4998","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=4998"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/4998\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=4998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=4998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=4998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}