I have some code that is currently using ThinkGeo Map Suite Services Edition to query a SQL Server 2008 database for the shape(s) that contain a point. That code is currently using Map Suite 6, but I am attempting to switch over to using Map Suite 9.
Dim sectionFeatures As Collection(Of Feature)
Dim sectionColumns As String() = {“SECTION”, “TOWNSHIP”}
sectionFeatures = sectionLayer.QueryTools.GetFeaturesContaining(inPoint, sectionColumns)
When I use Map Suite 6, the query that gets thrown at the database is
exec sp_executesql N’SELECT [SECTION],[TOWNSHIP],[Shape].STAsBinary() as [Shape],[SECTION_ID] FROM SECTION with(index(S868_idx)) WHERE (geography::STGeomFromText(@geography,4269).STIntersects(Shape)=1);’,N’@Geography varchar(170)’,@Geography=‘POLYGON((-110.7703329915 47.737164355451,-110.7703329915 47.737154355451,-110.7703229915 47.737154355451,-110.7703229915 47.737164355451,-110.7703329915 47.737164355451))’
When I use Map Suite 9 (yesterday’s daily build) the query instead is
exec sp_executesql N’SELECT [SECTION],[TOWNSHIP],[Shape].STAsBinary() as [Shape],[SECTION_ID] FROM SECTION WHERE (geometry::STGeomFromText(@Geography,4269).STWithin(geometry::STGeomFromWKB(Shape.STAsBinary(),4269))=1);’,N’@Geography varchar(38)’,@Geography='POINT(-110.7703279915 47.737159355451)'
The top (Map Suite 6) version is supplying the spatial index hint whereas the bottom (Map Suite 9) version is not. The top query completes in less than a second, the bottom one times out after the default 30 second timeout. My question is what do I need to do to get Map Suite 9 to generate SQL that takes advantage of the spatial index of the table? I can see by inspecting the properties of the layer in Visual Studio that the layer knows the name of the spatial index, but it isn’t currently using that index name in the query sent to the database and for some reason the database doesn’t appear to be smart enough to use the index unless it’s told to do so by the query.
Any advice would be appreciated.
Thanks,
John