I have database with geography polygons stored as text, for various reasons. I understand that this is not optimal for performance reasons (and this is fine), but it was surprising to me how much faster a query becomes by a somewhat counter-intuitive workaround. Example in pseudo-sql:
-- query style 1, about 40 seconds execution time
SELECT indexedGeography.STIntersection(geography::STGeomFromText(geographyText, 4326)).STArea() /indexedGeography.STArea()
FROM someTables
-- query style 2, about 3 seconds execution time
CREATE TABLE #tmp (geog geography)
INSERT INTO #tmp (geog) SELECT geography::STGeomFromText(geographyText, 4326) FROM someTables
CREATE SPATIAL INDEX [IX_Spatial] ON #tmp -- index syntax omitted
SELECT indexedGeography.STIntersection(#tmp.geog).STArea() /indexedGeography.STArea() FROM joinedTables
DROP TABLE #tmp
--------
So it feels like there is a possibility of a speedup if SQL Server could identify that it would be faster to under the hood run similar calculations for on-the-fly created geography in the execution plan as those that happen when CREATE SPATIAL INDEX explicitly is called.
Tested on SQL Server 2012. The results from both queries are as expected, and the workaround is ok, so I don't have a problematic issue with this, just leaving some feedback.
Best regards