{"id":664,"date":"2008-12-17T10:22:00","date_gmt":"2008-12-17T10:22:00","guid":{"rendered":"\/blogs\/bobb\/post\/Spatial-Index-Diagnostic-Procs-Intro.aspx"},"modified":"2013-01-03T23:59:47","modified_gmt":"2013-01-04T07:59:47","slug":"spatial-index-diagnostic-procs-intro","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-intro\/","title":{"rendered":"Spatial Index Diagnostic Procs &#8211; Intro"},"content":{"rendered":"<p>\nI&#39;ve been looking at the spatial index stored procedures (sp_help_spatial_geography_index_xml and friends) a little harder recently, in an attempt to help answer two questions.\n<\/p>\n<p>\n1. If I have a spatial query, why does\/doesn&#39;t it use my spatial index?<br \/>\n2. If I have a specific spatial query in mind, what are the best values to choose for my spatial index density?\n<\/p>\n<p>\nIn addition to the diagnostic information presented in the procs, there are a few things to keep in mind when attempting to answer the first question. Currently, the query optimizer is estimating &quot;high&quot; when it comes to using the spatial index, so there are occasions were the spatial index should be used and isn&#39;t. <a href=\"http:\/\/blogs.msdn.com\/b\/isaac\/\" class=\"broken_link\">Isaac<\/a> mentioned this in his PDC talk, and mentioned that this would be changed in the next refreshed. As far as I could see, it isn&#39;t in SQL Server 2008 CU2.\n<\/p>\n<p>\nAlso, remember that SQL Server will never use cardinality estimates for a parameter set in a variable by the SET statement unless you use OPTION(RECOMPILE) on the statement. This is a general SQL Server behavior, not a spatial behavior because of when SQL Server creates the query plan. So if you want cardinality estimates for the variable @g in the query &quot;select geog from table where geog.Intersects(@g)=1&quot; you must either pass @g in as a stored procedure parameter or use sp_executesql. Realize that if you use a parameterized query in a client app, the client API stacks will change the parameterized query to invoke sp_executesql, so you&#39;re OK here. According to Michael Rys&#39; SQLPASS talk, one spatial-specific behavior is that cardinality won&#39;t be used if @g if specified as a constant, that is &quot;select&#8230;where geog.Intersects(&#39;POINT(1 1)&#39;)=1 &quot; either. Finally SQL Server doesn&#39;t change the query plan in a parameter value changes, general behavior, not spatial-specific.\n<\/p>\n<p>\nBack to the diagnostic stored procs.\n<\/p>\n<p>\nThe information that the spatial index procs provide consists of three main categories:<br \/>\n1. Information about the index itself<br \/>\n2. Information about the query sample<br \/>\n3. How efficient the query index is when used against the query sample\n<\/p>\n<p>\nThe query sample is specified as an input parameter to the diagnostic procs, and would be &quot;@g&quot; in the Intersects queries above.\n<\/p>\n<p>\nIf you&#39;ve read my <a href=\"http:\/\/3.209.169.194\/blogs\/bobb\/using-the-spatial-index-diagnostic-stored-procedures\/\">previous blog post<\/a> on the diagnostic procs, read it again, I&#39;ve revised it. Filters are the subject of the next post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#39;ve been looking at the spatial index stored procedures (sp_help_spatial_geography_index_xml and friends) a little harder recently, in an attempt to help answer two questions. 1. If I have a spatial query, why does\/doesn&#39;t it use my spatial index? 2. If I have a specific spatial query in mind, what are the best values to choose [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,36],"tags":[],"class_list":["post-664","post","type-post","status-publish","format-standard","hentry","category-sql-server-2008","category-sql-server-spatial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spatial Index Diagnostic Procs - Intro - 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\/spatial-index-diagnostic-procs-intro\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spatial Index Diagnostic Procs - Intro - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"I&#039;ve been looking at the spatial index stored procedures (sp_help_spatial_geography_index_xml and friends) a little harder recently, in an attempt to help answer two questions. 1. If I have a spatial query, why does\/doesn&#039;t it use my spatial index? 2. If I have a specific spatial query in mind, what are the best values to choose [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-intro\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2008-12-17T10:22:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-01-04T07:59:47+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\/spatial-index-diagnostic-procs-intro\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-intro\/\",\"name\":\"Spatial Index Diagnostic Procs - Intro - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2008-12-17T10:22:00+00:00\",\"dateModified\":\"2013-01-04T07:59:47+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-intro\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-intro\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-intro\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server 2008\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sql-server-2008\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Spatial Index Diagnostic Procs &#8211; Intro\"}]},{\"@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":"Spatial Index Diagnostic Procs - Intro - 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\/spatial-index-diagnostic-procs-intro\/","og_locale":"en_US","og_type":"article","og_title":"Spatial Index Diagnostic Procs - Intro - Bob Beauchemin","og_description":"I&#39;ve been looking at the spatial index stored procedures (sp_help_spatial_geography_index_xml and friends) a little harder recently, in an attempt to help answer two questions. 1. If I have a spatial query, why does\/doesn&#39;t it use my spatial index? 2. If I have a specific spatial query in mind, what are the best values to choose [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-intro\/","og_site_name":"Bob Beauchemin","article_published_time":"2008-12-17T10:22:00+00:00","article_modified_time":"2013-01-04T07:59:47+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\/spatial-index-diagnostic-procs-intro\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-intro\/","name":"Spatial Index Diagnostic Procs - Intro - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2008-12-17T10:22:00+00:00","dateModified":"2013-01-04T07:59:47+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-intro\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-intro\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-intro\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"SQL Server 2008","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sql-server-2008\/"},{"@type":"ListItem","position":3,"name":"Spatial Index Diagnostic Procs &#8211; Intro"}]},{"@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\/664","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=664"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/664\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}