我有一个数据库,其中包含 2 000 000 行内的数据表,其中 1 个地理类型字段包含点。在另一个数据表中,我有 600 行,其中 1 个地理类型字段包含多边形。
This query to retrieve all the POINT in a POLYGON is very slow
SELECT ID_POINT, ID_POLYGON FROM
(SELECT ID_POINT, COORD FROM POINT_TABLE) as POINT
(SELECT ID_POLYGON, COORD FROM POLYGON_TABLE WHERE ID_POLYGON = 276) as POLYGON
WHERE
(POINT.Coord.STIntersects(POLYGON.COORD) = 1)
我在每个表中有 1 个空间索引,如下所示:
CREATE SPATIAL INDEX [IDX_POLYGON_COORD] ON [dbo].[POLYGON]
(
[COORD]
)USING GEOGRAPHY_GRID
WITH (
GRIDS =(LEVEL_1 = MEDIUM,LEVEL_2 = MEDIUM,LEVEL_3 = MEDIUM,LEVEL_4 = MEDIUM),
CELLS_PER_OBJECT = 16, PAD_INDEX = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
你能帮我加快这个查询吗?
问候