I have a very simple table structure which is using spatial data:
CREATE TABLE Test
(
[ID] int not null,
[GeoLocation] geometry not null,
CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED
(
[ID] ASC
)) on [PRIMARY]
Here it is the DDL for the spatial index:
CREATE SPATIAL INDEX [IX_GeoLocation_Geo] ON dbo.[Test]
(
GeoLocation
)USING GEOMETRY_GRID
WITH (BOUNDING_BOX =(-180, -90, 180, 90), GRIDS =(LEVEL_1 = MEDIUM,LEVEL_2 = MEDIUM,LEVEL_3 = MEDIUM,LEVEL_4 = MEDIUM), CELLS_PER_OBJECT = 1024, PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
I have the primary key on the [ID]
column and a spatial index on the GeoLocation
column. For the spatial index I am using tessellation schema "Geometry auto grid".
Even I have only several thousands rows in the database, the query getting the nearest neighbor is pretty slow.
SELECT top 15 T.ID
FROM dbo.TestT --with(index(IX_SpatialData_Geo))
WHERE T.Geo.Filter(@region) = 1
Actually, by adding the table hint, (forcing the using of spatial index) the query's performance is going down instead of increasing the performances :)
Thanks