I have two MS SQL Server (v11.0) tables with Geometry datatypes. One has ~8000 point records, the other ~100 polygon records.
Both tables have spatial indexes on the appropriate geometry column and both use the same SRID.
For a specified reporting purpose, I need to extract a list of names of all the points with the name of the polygon within which it lies. All points are within one of the polygons. The polygons do not overlap.
I use this query:
SELECT points.point_label, polygons.polygon_label
FROM
points WITH (NOLOCK) INNER JOIN
polygons WITH (NOLOCK) ON
polygons.polygon_geometry.STContains(points.point_geometry) = 1
It works, but is very slow to return all ~8000 points rows with the containing polygon label.
Is there a more efficient way of joining them to achieve my desired outcome? Is SQL Server just not very good at calculating geometric stuff against datasets? Most of the code examples I see just involve a geometry type variable with a single value being operated on.