0

我正在尝试查询最近邻居的地理点,无论我是否使用空间索引,我总是得到相似的时间,大约需要 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);
4

1 回答 1

0

试试这个,似乎它可能是一个类似的问题,也许它没有使用空间索引。——</p>

于 2012-08-14T11:55:31.310 回答