{"id":660,"date":"2008-12-18T13:07:00","date_gmt":"2008-12-18T13:07:00","guid":{"rendered":"\/blogs\/bobb\/post\/Spatial-Index-Diagnostic-Procs-The-Rest-of-the-Story.aspx"},"modified":"2008-12-18T13:07:00","modified_gmt":"2008-12-18T13:07:00","slug":"spatial-index-diagnostic-procs-the-rest-of-the-story","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-the-rest-of-the-story\/","title":{"rendered":"Spatial Index Diagnostic Procs &#8211; The Rest of the Story"},"content":{"rendered":"<p>\nI&#39;ve devoted the last few blog entries to describing what&#39;s in that spatial index analysis proc output and how to use it and interpret the results. Just wanted to describe the rest of the information and how the information relates to what you&#39;d find in a query plan that uses a spatial index.\n<\/p>\n<p>\nThe procs return:<br \/>\n1. Information about the index<br \/>\n2. Information about the query sample<br \/>\n3. How efficient the index is when used against the query sample\n<\/p>\n<p>\nThe information you get about the index is: <br \/>\n&#8211;&nbsp; Bounding Box dimensions &#8211; BOL says they are NULL for geography but they are always -180, -90, 180, 90 for geography<br \/>\n&#8211;&nbsp; GridLevelSize &#8211; 4 levels<br \/>\n&#8211;&nbsp; Cells_Per_Object &#8211; maximum tessellated cells per row, specified in DDL<br \/>\n&#8211;&nbsp; Page and Row counts for the spatial&nbsp;index<br \/>\n&#8211;&nbsp; Avg number of cells per base row (how many of the CellsPerObject were actually used)<br \/>\n&#8211;&nbsp; Height, Width, Area of a cell &#8211; Geography is always the same, but its nice to know how big the cells are compared to the other levels. Not sure what the unit of measure is for geography (BOL says &quot;depends&nbsp;on SRID&quot;), by looking at the number it doesn&#39;t look like it could be meters.<br \/>\n&#8211;&nbsp; CellAreaToBoundingBox percentage &#8211; 4 levels<br \/>\n&#8211;&nbsp; Total SRIDs found\n<\/p>\n<p>\nThe most interesting is likely the info about the number of cells in each level (including level0 &#8211; off the bounding box). Any levels that are 0 rows don&#39;t appear in the XML output. You get info for:<br \/>\n-Number of Object Cells for Index <br \/>\n-Number of Interior Cells <br \/>\n-Number of Intersecting Cells<br \/>\n-Number of Border Cells<br \/>\n-also some numbers about cells normalized to the leaf grid\n<\/p>\n<p>\nThe cells are useful in how they relate to the primary filter. The interior, intersecting, and border cells are used by the internal filter.\n<\/p>\n<p>\nFor the query sample, you get the same cells numbers. No &quot;cells normalized to the leaf&quot; however. BTW, for the geography index ignore the BOL comment that indicates that if Level0 of the query sample is 1 then index is not useable for this query. For geography its always 1.\n<\/p>\n<p>\nThis relates to the following information that appears in a query plan that uses spatial indexes.<br \/>\n1. All of the query samples (in the spatial predicate) are tessellated using the same parameters (density\/max cells)<br \/>\n2. The table is joined against all parent\/children of the index (the index levels are actually a hierarchy)<br \/>\n3. Index ranges are calculated<br \/>\n4. A join of the tesselated samples on index is done. This results in the number of rows selected by the primary filter.<br \/>\n5. The internal and secondary filters are applied in a separate query iterator (of type Filter) later on in the plan.\n<\/p>\n<p>\nThe upshot of this is that, not only is the index dimensions used to tessellate the base table rows, the same dimensions as the&nbsp;index&nbsp;are used to tessellate the query sample for the spatial predicate (query sample, in the sproc). So, for example, I&#39;d always thought that spatial indexes over points should specify all-HIGH density and maybe 2 max cells per object. But if your query sample contains large polygons, those same dimensions will be used against the query sample too. So maybe all-HIGH density for point-based indexes isn&#39;t a hard and fast rule.\n<\/p>\n<p>\nHopefully this should give you enough information to investigate your indexes and queries using the spatial analysis stored procs. As far as patterns for &quot;which specifications of index is best&quot;, more patterns will show up as I investigate more different patterns of spatial data. For now, I&#39;m dividing these into three main categories:\n<\/p>\n<p>\n1. Spatial index over table of points, Query sample is polygon.<br \/>\n2. Spatial index over table of polygons, Query sample is point.<br \/>\n3. Spatial index over table of polygons, Query sample is polygon.\n<\/p>\n<p>\nWith the simplifying premise that linestrings are thin like a point (ie they won&#39;t fill a cell), but if you put a STBuffer around them, they&#39;re more like polygons.\n<\/p>\n<p>\nHappy index hunting.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#39;ve devoted the last few blog entries to describing what&#39;s in that spatial index analysis proc output and how to use it and interpret the results. Just wanted to describe the rest of the information and how the information relates to what you&#39;d find in a query plan that uses a spatial index. The procs [&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-660","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 - The Rest of the Story - 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-the-rest-of-the-story\/\" \/>\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 - The Rest of the Story - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"I&#039;ve devoted the last few blog entries to describing what&#039;s in that spatial index analysis proc output and how to use it and interpret the results. Just wanted to describe the rest of the information and how the information relates to what you&#039;d find in a query plan that uses a spatial index. The procs [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-the-rest-of-the-story\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2008-12-18T13:07: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=\"3 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-the-rest-of-the-story\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-the-rest-of-the-story\/\",\"name\":\"Spatial Index Diagnostic Procs - The Rest of the Story - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2008-12-18T13:07:00+00:00\",\"dateModified\":\"2008-12-18T13:07:00+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-the-rest-of-the-story\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-the-rest-of-the-story\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-the-rest-of-the-story\/#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; The Rest of the Story\"}]},{\"@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 - The Rest of the Story - 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-the-rest-of-the-story\/","og_locale":"en_US","og_type":"article","og_title":"Spatial Index Diagnostic Procs - The Rest of the Story - Bob Beauchemin","og_description":"I&#39;ve devoted the last few blog entries to describing what&#39;s in that spatial index analysis proc output and how to use it and interpret the results. Just wanted to describe the rest of the information and how the information relates to what you&#39;d find in a query plan that uses a spatial index. The procs [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-the-rest-of-the-story\/","og_site_name":"Bob Beauchemin","article_published_time":"2008-12-18T13:07:00+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-the-rest-of-the-story\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-the-rest-of-the-story\/","name":"Spatial Index Diagnostic Procs - The Rest of the Story - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2008-12-18T13:07:00+00:00","dateModified":"2008-12-18T13:07:00+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-the-rest-of-the-story\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-the-rest-of-the-story\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/spatial-index-diagnostic-procs-the-rest-of-the-story\/#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; The Rest of the Story"}]},{"@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\/660","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=660"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/660\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}