Spatial index performance tuning
Getting a really good spatial index on a geography column took a lot more effort and reading than I'd ever have dreamed of! It's really hard to find good resources on them so I thought I'd type up a few of the things I've learnt over the last few days trying to get some query times down. Our queries ended up running in about 1 tenth the time as they did with the first attempt at a spatial index. However, even that first index sped the queries up by about 10x. Which leads me to my first point: Any spatial index is always better than not having one. Hang on Rob, what queries?! Good question! In the database we have a few thousand administrative boundaries that we want to ask questions about, for the sake of this post (and of tuning the index) our main question is: What boundaries is a point p in? In SQL this looks like: DECLARE @ p geography SET @ p = geography::Point( - 35 , 139 , 4326 ) SELECT BoundaryName FROM dbo.Boundaries WHERE data .STInter...