{"id":471,"date":"2012-09-22T12:15:00","date_gmt":"2012-09-22T12:15:00","guid":{"rendered":"\/blogs\/bobb\/post\/Selective-XML-Indexes-in-SQL-Server-First-Tryit-works.aspx"},"modified":"2012-09-22T12:15:00","modified_gmt":"2012-09-22T12:15:00","slug":"selective-xml-indexes-in-sql-server-first-try-it-works","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/","title":{"rendered":"Selective XML Indexes in SQL Server &#8211; First Try&#8230;it works"},"content":{"rendered":"<p>\nOK, so let&#39;s try something. Load a bunch of documents. Although, actually this part works with an empty table.\n<\/p>\n<p>\ncreate selective xml index fooidx2 on foo(thexml)<br \/>\nfor<br \/>\n(<br \/>\npathname1 = &#39;foo\/bar\/baz2&#39;<br \/>\n);\n<\/p>\n<p>\nMsg 6379, Level 16, State 201, Line 1<br \/>\nselective XML index &#39;fooidx&#39; already exists on column &#39;thexml&#39; in table &#39;foo&#39;. <br \/>\nMultiple selective XML indexes per column are not allowed.\n<\/p>\n<p>\nOnly one SXI&nbsp;at a time. With 1-n path specifications.\n<\/p>\n<p>\nAbout path specifications. To paraphrase the talk&#8230;there are three basic types of paths.\n<\/p>\n<p>\n1. Simple: \/foo\/bar\/baz1<br \/>\n2. With optimizations:<br \/>\n&nbsp;&nbsp; \/foo\/bar\/baz2 as XQUERY &#39;xs:string&#39; MAXLENGTH(25)<br \/>\n&nbsp;&nbsp; \/foo\/bar\/baz3 as XQUERY &#39;xs:double&#39; SINGLETON<br \/>\n&nbsp;&nbsp; \/foo\/bar\/baz4 as XQUERY node() &#8212; check for node existance<br \/>\n3. For use with the XQuery value method:<br \/>\n&nbsp;&nbsp; \/foo\/bar\/baz5 as SQL VARCHAR(25)\n<\/p>\n<p>\nForms 1 and 2 are for XQuery with any XQuery method. Form 3 is for XQuery value method. This seems to turn out to be more important than I thought it was at first.\n<\/p>\n<p>\nRule for using it in query plan:<br \/>\n&nbsp;&nbsp; 1. If SXI (selective XML index) exists and path matches specification, use it<br \/>\n&nbsp;&nbsp; 2. If PXI (primary XML index) exists, use it<br \/>\n&nbsp;&nbsp; 3. Else use XML Reader with XPath Filter\n<\/p>\n<p>\nFirst experiment:\n<\/p>\n<p>\nDefined (the one and only one) SXI index for this XML column&nbsp;on path \/foo\/bar\/baz. Type 1 path specification. Issued query:\n<\/p>\n<p>\nSELECT thexml.value(&#39;(\/foo\/bar\/baz)[1]&#39;, &#39;varchar(25)&#39;)<br \/>\nFROM foo;\n<\/p>\n<p>\nSXI isn&#39;t used in the plan. Hmm&#8230;he said it was a decision of the algebrizer, not the optimizer. And path sure looks like it matches. Futz with this for an hour or so. I actually added more documents. Used three path specs&nbsp;that (I thought) all matched. I&nbsp;thought this worked in his demo, but no joy.&nbsp;Tried to force the SXI with&nbsp;index hint&nbsp;(you can&#39;t force an SXI in any case). But it&#39;s the algebrizer, not the optimizer, Bob&#8230;\n<\/p>\n<p>\nInstead try index on \/foo\/bar\/baz AS SQL VARCHAR(25). Type 3 path specification.&nbsp;Now, it&#39;s used.\n<\/p>\n<p>\n@bobbeauch<\/p>\n","protected":false},"excerpt":{"rendered":"<p>OK, so let&#39;s try something. Load a bunch of documents. Although, actually this part works with an empty table. create selective xml index fooidx2 on foo(thexml) for ( pathname1 = &#39;foo\/bar\/baz2&#39; ); Msg 6379, Level 16, State 201, Line 1 selective XML index &#39;fooidx&#39; already exists on column &#39;thexml&#39; in table &#39;foo&#39;. Multiple selective XML [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,37],"tags":[],"class_list":["post-471","post","type-post","status-publish","format-standard","hentry","category-sql-server-2012","category-sql-server-xml"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Selective XML Indexes in SQL Server - First Try...it works - Bob Beauchemin<\/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\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Selective XML Indexes in SQL Server - First Try...it works - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"OK, so let&#039;s try something. Load a bunch of documents. Although, actually this part works with an empty table. create selective xml index fooidx2 on foo(thexml) for ( pathname1 = &#039;foo\/bar\/baz2&#039; ); Msg 6379, Level 16, State 201, Line 1 selective XML index &#039;fooidx&#039; already exists on column &#039;thexml&#039; in table &#039;foo&#039;. Multiple selective XML [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2012-09-22T12:15:00+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\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\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/\",\"name\":\"Selective XML Indexes in SQL Server - First Try...it works - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2012-09-22T12:15:00+00:00\",\"dateModified\":\"2012-09-22T12:15:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server 2012\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sql-server-2012\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Selective XML Indexes in SQL Server &#8211; First Try&#8230;it works\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Selective XML Indexes in SQL Server - First Try...it works - Bob Beauchemin","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\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/","og_locale":"en_US","og_type":"article","og_title":"Selective XML Indexes in SQL Server - First Try...it works - Bob Beauchemin","og_description":"OK, so let&#39;s try something. Load a bunch of documents. Although, actually this part works with an empty table. create selective xml index fooidx2 on foo(thexml) for ( pathname1 = &#39;foo\/bar\/baz2&#39; ); Msg 6379, Level 16, State 201, Line 1 selective XML index &#39;fooidx&#39; already exists on column &#39;thexml&#39; in table &#39;foo&#39;. Multiple selective XML [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/","og_site_name":"Bob Beauchemin","article_published_time":"2012-09-22T12:15:00+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/","name":"Selective XML Indexes in SQL Server - First Try...it works - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2012-09-22T12:15:00+00:00","dateModified":"2012-09-22T12:15:00+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-indexes-in-sql-server-first-try-it-works\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"SQL Server 2012","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sql-server-2012\/"},{"@type":"ListItem","position":3,"name":"Selective XML Indexes in SQL Server &#8211; First Try&#8230;it works"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=471"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/471\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}