我正在尝试查询最近邻居的地理位置,无论我是否使用空间索引,我总是得到类似的时间,大约需要6秒。如何加快查询速度?
这是我的问题:
Declare @param nvarchar(50);
set @param = 'POINT(32.489491 37.864724)'
Declare @paramGeom geometry = geometry::STPointFromText(@param, 4326);
Select top 1 MI_PRINX, MI_STYLE, TrafikIsigi, Demiryolu, UlkeSinir, ID, SP_GEOMETRY.STX AS Longitude, SP_GEOMETRY.STY AS Latitude, SP_GEOMETRY AS Geometry FROM dbo.NODE (nolock)
WHERE NODE.SP_GEOMETRY.STDistance(@paramGeom) < 0.1
ORDER BY NODE.SP_GEOMETRY.STDistance(@paramGeom);
这是我的索引:
CREATE SPATIAL INDEX [IX_Spatial] ON [dbo].[NODE]
(
[SP_GEOMETRY]
)USING GEOMETRY_GRID
WITH (
BOUNDING_BOX =(25, 35, 46, 43), GRIDS =(LEVEL_1 = HIGH,LEVEL_2 = MEDIUM,LEVEL_3 = MEDIUM,LEVEL_4 = MEDIUM),
CELLS_PER_OBJECT = 64, PAD_INDEX = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
任何帮助将不胜感激。
修改/溶液
我改变了我的查询:
Declare @param nvarchar(50);
set @param = 'POINT(32.489491 37.864724)'
Declare @paramGeom geometry = geometry::STPointFromText(@param, 4326);
Select top 1 MI_PRINX, MI_STYLE, TrafikIsigi, Demiryolu, UlkeSinir, ID, SP_GEOMETRY.STX AS Longitude, SP_GEOMETRY.STY AS Latitude, SP_GEOMETRY AS Geometry FROM [dbo].[NODE] n WITH (INDEX(IX_Spatial))
WHERE n.SP_GEOMETRY.STDistance(@paramGeom) < 0.1
ORDER BY n.SP_GEOMETRY.STDistance(@paramGeom);