<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Isaac @ MSDN : spatial indexing</title><link>http://blogs.msdn.com/isaac/archive/tags/spatial+indexing/default.aspx</link><description>Tags: spatial indexing</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Basic Multi-Level Grids</title><link>http://blogs.msdn.com/isaac/archive/2008/03/01/basic-multi-level-grids.aspx</link><pubDate>Sat, 01 Mar 2008 05:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7968742</guid><dc:creator>isaac</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/isaac/comments/7968742.aspx</comments><wfw:commentRss>http://blogs.msdn.com/isaac/commentrss.aspx?PostID=7968742</wfw:commentRss><wfw:comment>http://blogs.msdn.com/isaac/rsscomments.aspx?PostID=7968742</wfw:comment><description>&lt;P&gt;Hi Folks,&lt;/P&gt;
&lt;P&gt;&lt;A class="" href="http://blogs.msdn.com/isaac/archive/2008/02/05/picking-up-on-indexing-moving-beyond-the-simple-grid.aspx" mce_href="http://blogs.msdn.com/isaac/archive/2008/02/05/picking-up-on-indexing-moving-beyond-the-simple-grid.aspx"&gt;Last time&lt;/A&gt;, we highlighted several problems with a simple grid index.&amp;nbsp; If you don't recall---and since it's been a while, that wouldn't be a surprise---you may want to review them.&amp;nbsp; In this post I'll start to describe how we get around them.&lt;/P&gt;
&lt;P&gt;In SQL Server, we don't use a simple grid like the one described.&amp;nbsp; Instead, we use a multi-level grid, which ends up looking very much like a quad tree.&amp;nbsp; Basically, instead of having one grid level, we have four, with each lower-level grid nested in the one above.&lt;/P&gt;
&lt;P&gt;Let's look at an example.&amp;nbsp; If we have a 2x2 grid at each level, then we can tile the object below with three tiles at the top-level grid:&lt;/P&gt;
&lt;P&gt;&lt;IMG style="WIDTH: 330px; HEIGHT: 330px" height=330 src="http://blogs.msdn.com/photos/isaac/images/7968868/original.aspx" width=330 mce_src="http://blogs.msdn.com/photos/isaac/images/7968868/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;These tiles cover the object, which is a property we want to maintain for our indexing scheme, but there's a lot of extra coverage.&amp;nbsp; This extra means we're likely to have a good number of false positives from our primary filter.&amp;nbsp; We can go to a second-level gridding instead:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 330px; HEIGHT: 330px" height=330 src="http://blogs.msdn.com/photos/isaac/images/7968975/original.aspx" width=330 mce_src="http://blogs.msdn.com/photos/isaac/images/7968975/original.aspx"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;At this level, we've trimmed some of the extra slop from the edges, but our description of the object has become more complex as well.&amp;nbsp;&amp;nbsp;With our four levels, we can push this even further---here's what a fourth-level tiling of the object would look like:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 330px; HEIGHT: 330px" height=330 src="http://blogs.msdn.com/photos/isaac/images/7968875/original.aspx" width=330 mce_src="http://blogs.msdn.com/photos/isaac/images/7968875/original.aspx"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;This description is nice and tight---there's very extra covering of the object---but it's also very complicated.&amp;nbsp; What's key to&amp;nbsp;keeping the complexity down is that&amp;nbsp;we don't require that all object use the same level tiling, nor do we require that all tiles for a particular object all be at the same level.&amp;nbsp; We can mix as we wish.&lt;/P&gt;
&lt;P mce_keep="true"&gt;The ability to mix levels in our tiling leads us to two optimizations.&amp;nbsp; The first, which is always used, is that if we find that all subtiles of a particular tile are touched by the object, then we won't further subdivide the cell.&amp;nbsp; Subdividing gives us nothing but more cells.&amp;nbsp; Perhaps this is clearer visually; below is a picture of the same tiling above with this optimization applied:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 330px; HEIGHT: 330px" height=330 src="http://blogs.msdn.com/photos/isaac/images/7968877/original.aspx" width=330 mce_src="http://blogs.msdn.com/photos/isaac/images/7968877/original.aspx"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;As you can see, this greatly reduces the number of tiles we have, and does so by mixing levels.&amp;nbsp; A second way to reduce tiles is through an explicit limit.&amp;nbsp; We default this limit to 16, but the user can tweak it to their liking.&amp;nbsp; When we decompose an object, we do a breath-first walk down the tree decomposing tiles, and we stop when we hit the pre-defined limit.&amp;nbsp; E.g., we might end up with:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 330px; HEIGHT: 330px" height=330 src="http://blogs.msdn.com/photos/isaac/images/7968888/original.aspx" width=330 mce_src="http://blogs.msdn.com/photos/isaac/images/7968888/original.aspx"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;There's much more to say about this, but before I leave it for now, let me point out that&amp;nbsp;while these examples use 2x2 decompositions at each level, we&amp;nbsp;use more.&amp;nbsp; The exact amount is, in fact, adjustable: the user can set each level to low (4x4) medium (8x8) or high&amp;nbsp;(16x16).&lt;/P&gt;
&lt;P mce_keep="true"&gt;How should the user tweak these various parameters?&amp;nbsp; It's hard to give general advice, as it's a very data- and query-dependent calculation, but we feel that we have picked some defaults that will work well for most people.&amp;nbsp; We may have better advice as more people start using the index and we get reports on what worked for them.&amp;nbsp; (Yes, we're begging you to send us your findings!)&lt;/P&gt;
&lt;P mce_keep="true"&gt;Next&amp;nbsp;time we'll continue with some more details about the mult-level grid.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Cheers,&lt;BR&gt;-Isaac&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7968742" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/isaac/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://blogs.msdn.com/isaac/archive/tags/spatial/default.aspx">spatial</category><category domain="http://blogs.msdn.com/isaac/archive/tags/spatial+indexing/default.aspx">spatial indexing</category></item></channel></rss>