{"id":469,"date":"2012-09-22T16:12:00","date_gmt":"2012-09-22T16:12:00","guid":{"rendered":"\/blogs\/bobb\/post\/Selective-XML-Index-Secondary-Selective-XML-Indices.aspx"},"modified":"2012-09-22T16:12:00","modified_gmt":"2012-09-22T16:12:00","slug":"selective-xml-index-secondary-selective-xml-indices","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-index-secondary-selective-xml-indices\/","title":{"rendered":"Selective XML Index &#8211; Secondary Selective XML Indices"},"content":{"rendered":"<p>\nI&#39;ve only been talking so far about the &quot;primary&quot; Selective XML Index. But you can also create 0-n &quot;secondary&quot; Selective XML Indexes. The syntax looks a little bit like secondary &quot;non-selective&quot; XML Indexes in that you use the &quot;USING [related XML index]&quot;. You specify one (and only one) pathspec. Additionally, the XML value that the pathspec &quot;points to&quot; (see previous post) cannot be data type xs:untypedAtomic (varbinary(max)).\n<\/p>\n<p>\ncreate xml index sxi_secondary1 on foo(thexml)<br \/>\nusing xml index fooidx<br \/>\nfor (pathname1); &#8212; strongly typed to SQLVARCHAR(25)\n<\/p>\n<p>\ncreate xml index sxi_secondary2 on foo(thexml)<br \/>\nusing xml index fooidx<br \/>\nfor (anotherxq); &#8212; strongly typed to XQUERY xs:double (SQL FLOAT)\n<\/p>\n<p>\n&#8212; Msg 102, Level 15, State 1, Line 3<br \/>\n&#8212; Incorrect syntax near &#39;,&#39;. <br \/>\n&#8212; Means: error: only one pathspec name allowed<br \/>\ncreate xml index sxi_secondary3 on foo(thexml)<br \/>\nusing xml index fooidx<br \/>\nfor (pathname1, pathname2);\n<\/p>\n<p>\n&#8212; Msg 6391, Level 16, State 0, Line 1<br \/>\n&#8212; Path &#39;pathname2&#39; is promoted to a type that is invalid for use as a key column in a secondary selective XML index.\n<\/p>\n<p>\n&#8212; Means: can&#39;t have varbinary(max) as index key<br \/>\ncreate xml index sxi_secondary3 on foo(thexml)<br \/>\nusing xml index fooidx<br \/>\nfor (pathname2);\n<\/p>\n<p>\nThese work the way you&#39;d think. They create a NONCLUSTERED index over the (internal) table that comprises the &quot;primary&quot; Selective XML Index. The NONCLUSTERED index key is the &quot;value&quot; column in the path spec, along with the traditional &quot;backpointer&quot; to the primary key of the &quot;primary&quot; Selective XML index. These NONCLUSTERED index are FILTERED indexes, filtered on the value column in the path spec.The filter is &quot;[Valuecolumn] IS NOT NULL&quot;\n<\/p>\n<p>\nSo, if an XML value in a pathspec is sparse (meaning, it doesn&#39;t appear in every\/most rows) these secondary Selective XML Indexes could be helpful. And remember, like Michael said, these indexes are chosen by the optimizer, not the algebrizer, until the way the algebrizer chooses the primary Selective XML index, but after the algebrizer decides that the Selective XML Index could be useful at all.\n<\/p>\n<p>\n@bobbeauch<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#39;ve only been talking so far about the &quot;primary&quot; Selective XML Index. But you can also create 0-n &quot;secondary&quot; Selective XML Indexes. The syntax looks a little bit like secondary &quot;non-selective&quot; XML Indexes in that you use the &quot;USING [related XML index]&quot;. You specify one (and only one) pathspec. Additionally, the XML value that the [&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-469","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 Index - Secondary Selective XML Indices - 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-index-secondary-selective-xml-indices\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Selective XML Index - Secondary Selective XML Indices - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"I&#039;ve only been talking so far about the &quot;primary&quot; Selective XML Index. But you can also create 0-n &quot;secondary&quot; Selective XML Indexes. The syntax looks a little bit like secondary &quot;non-selective&quot; XML Indexes in that you use the &quot;USING [related XML index]&quot;. You specify one (and only one) pathspec. Additionally, the XML value that the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-index-secondary-selective-xml-indices\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2012-09-22T16:12: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-index-secondary-selective-xml-indices\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-index-secondary-selective-xml-indices\/\",\"name\":\"Selective XML Index - Secondary Selective XML Indices - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2012-09-22T16:12:00+00:00\",\"dateModified\":\"2012-09-22T16:12:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-index-secondary-selective-xml-indices\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-index-secondary-selective-xml-indices\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-index-secondary-selective-xml-indices\/#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 Index &#8211; Secondary Selective XML Indices\"}]},{\"@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 Index - Secondary Selective XML Indices - 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-index-secondary-selective-xml-indices\/","og_locale":"en_US","og_type":"article","og_title":"Selective XML Index - Secondary Selective XML Indices - Bob Beauchemin","og_description":"I&#39;ve only been talking so far about the &quot;primary&quot; Selective XML Index. But you can also create 0-n &quot;secondary&quot; Selective XML Indexes. The syntax looks a little bit like secondary &quot;non-selective&quot; XML Indexes in that you use the &quot;USING [related XML index]&quot;. You specify one (and only one) pathspec. Additionally, the XML value that the [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-index-secondary-selective-xml-indices\/","og_site_name":"Bob Beauchemin","article_published_time":"2012-09-22T16:12: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-index-secondary-selective-xml-indices\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-index-secondary-selective-xml-indices\/","name":"Selective XML Index - Secondary Selective XML Indices - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2012-09-22T16:12:00+00:00","dateModified":"2012-09-22T16:12:00+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-index-secondary-selective-xml-indices\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-index-secondary-selective-xml-indices\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/selective-xml-index-secondary-selective-xml-indices\/#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 Index &#8211; Secondary Selective XML Indices"}]},{"@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\/469","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=469"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/469\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}