0

I am trying to query geopoints for nearest neighbour, Whether I use spatial index or not, I always get similar times and it takes about 6 seconds. How can I speed this query up?

Here is my query:

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);

Here is my Index:

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

Any help will be appreciated.

EDIT/SOLUTION:

I changed my query like this:

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);
  • I think this question is better suited for gis.stackexchange.com. And your question is confusing. Can't understand what you want. – Divi Aug 14 '12 at 10:52
  • I need to speed-up my query. This query takes about 6 seconds in 2M Node. – Mehmet Salih Yildirim Aug 14 '12 at 10:54
  • Try this http://stackoverflow.com/questions/3350965/how-can-i-speed-up-this-sql-server-spatial-query, it seems like it might be a similar problem and maybe its not using the spatial index. – Divi Aug 14 '12 at 10:57

1 Answers1

0

Try this, it seems like it might be a similar problem and maybe its not using the spatial index. –

Community
  • 1
  • 1
Divi
  • 7,621
  • 13
  • 47
  • 63