{"id":472,"date":"2012-09-22T11:59:00","date_gmt":"2012-09-22T11:59:00","guid":{"rendered":"\/blogs\/bobb\/post\/Getting-started-with-Selective-XML-Indexes-in-SQL-Server.aspx"},"modified":"2012-09-22T11:59:00","modified_gmt":"2012-09-22T11:59:00","slug":"getting-started-with-selective-xml-indexes-in-sql-server","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/getting-started-with-selective-xml-indexes-in-sql-server\/","title":{"rendered":"Getting started with Selective XML Indexes in SQL Server"},"content":{"rendered":"<p>\nSo, it was announced that SQL2012 SP1 CTP4 was released yesterday. You&#39;ve likely already heard this (more than once, everyone seems to revel in repeating announcements&nbsp;from the team). And it contains a new feature (I was surprised, thought that wasn&#39;t supposed to happen, new features in service packs, meanwhile&#8230;) called Selective XML Indexes. Interesting concept, especially because dragging around a primary XML index that&#39;s 3-6 bigger than the data itself&nbsp;is a burden. But, without it, querying on any non-trivial XML is quite slow. To put it nicely&#8230;\n<\/p>\n<p>\nDownloaded and installed the SP (remember its a CTP,&nbsp;DON&#39;T install this on a production system). Got my XML test bed out to try. First problem: no docs on the feature. Well, the only information that exists (OK, that I could find quickly) is in Michael Rys&#39; TechEd US\/Europe talks. Downloaded, listened to them, you can find&nbsp;them with a web search. I&#39;ll try not to repeat his content. There&#39;s DDL&nbsp;in his talk. So:\n<\/p>\n<p>\ncreate table foo (id int identity primary key, thexml xml);\n<\/p>\n<p>\ncreate selective xml index fooidx on foo(thexml)<br \/>\nfor<br \/>\n(<br \/>\npathname1 = &#39;foo\/bar\/baz&#39;,<br \/>\npathname2 = &#39;foo\/bar2&#39;<br \/>\n);\n<\/p>\n<p>\nMsg 9539, Level 16, State 1, Line 1<br \/>\nSelective XML Index feature is not supported for the current database version\n<\/p>\n<p>\nBummer. Really? Well, there is a trick to it (thanks, Michael).\n<\/p>\n<p>\nexec sys.sp_db_selective_xml_index null, &#39;on&#39; &#8212; turn on for current database\n<\/p>\n<p>\nBTW, if you want to restore\/attach this database now to a pre-SP1 system, you have to turn the feature off.\n<\/p>\n<p>\nexec sys.sp_db_selective_xml_index null, &#39;off&#39;\n<\/p>\n<p>\nWhich likely means deleting all the selective XML index stuff you have in the database too. Haven&#39;t tried it yet, though. And first parameter is the database name. NULL means &quot;current database&quot;.\n<\/p>\n<p>\nAnd it works now. So now we can all play along at home. \ud83d\ude09 Let a hundred selective XML indexes bloom. Michael suggests there will be BIG performance improvements and little&nbsp;disk space&nbsp;used.\n<\/p>\n<p>\n@bobbeauch<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, it was announced that SQL2012 SP1 CTP4 was released yesterday. You&#39;ve likely already heard this (more than once, everyone seems to revel in repeating announcements&nbsp;from the team). And it contains a new feature (I was surprised, thought that wasn&#39;t supposed to happen, new features in service packs, meanwhile&#8230;) called Selective XML Indexes. Interesting concept, [&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-472","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>Getting started with Selective XML Indexes in SQL Server - 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\/getting-started-with-selective-xml-indexes-in-sql-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting started with Selective XML Indexes in SQL Server - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"So, it was announced that SQL2012 SP1 CTP4 was released yesterday. You&#039;ve likely already heard this (more than once, everyone seems to revel in repeating announcements&nbsp;from the team). And it contains a new feature (I was surprised, thought that wasn&#039;t supposed to happen, new features in service packs, meanwhile&#8230;) called Selective XML Indexes. Interesting concept, [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/getting-started-with-selective-xml-indexes-in-sql-server\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2012-09-22T11:59: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\/getting-started-with-selective-xml-indexes-in-sql-server\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/getting-started-with-selective-xml-indexes-in-sql-server\/\",\"name\":\"Getting started with Selective XML Indexes in SQL Server - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2012-09-22T11:59:00+00:00\",\"dateModified\":\"2012-09-22T11:59:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/getting-started-with-selective-xml-indexes-in-sql-server\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/getting-started-with-selective-xml-indexes-in-sql-server\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/getting-started-with-selective-xml-indexes-in-sql-server\/#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\":\"Getting started with Selective XML Indexes in SQL Server\"}]},{\"@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":"Getting started with Selective XML Indexes in SQL Server - 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\/getting-started-with-selective-xml-indexes-in-sql-server\/","og_locale":"en_US","og_type":"article","og_title":"Getting started with Selective XML Indexes in SQL Server - Bob Beauchemin","og_description":"So, it was announced that SQL2012 SP1 CTP4 was released yesterday. You&#39;ve likely already heard this (more than once, everyone seems to revel in repeating announcements&nbsp;from the team). And it contains a new feature (I was surprised, thought that wasn&#39;t supposed to happen, new features in service packs, meanwhile&#8230;) called Selective XML Indexes. Interesting concept, [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/getting-started-with-selective-xml-indexes-in-sql-server\/","og_site_name":"Bob Beauchemin","article_published_time":"2012-09-22T11:59: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\/getting-started-with-selective-xml-indexes-in-sql-server\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/getting-started-with-selective-xml-indexes-in-sql-server\/","name":"Getting started with Selective XML Indexes in SQL Server - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2012-09-22T11:59:00+00:00","dateModified":"2012-09-22T11:59:00+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/getting-started-with-selective-xml-indexes-in-sql-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/getting-started-with-selective-xml-indexes-in-sql-server\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/getting-started-with-selective-xml-indexes-in-sql-server\/#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":"Getting started with Selective XML Indexes in SQL Server"}]},{"@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\/472","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=472"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/472\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}