我有一个非常简单的表结构,它使用空间数据:
CREATE TABLE Test
(
[ID] int not null,
[GeoLocation] geometry not null,
CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED
(
[ID] ASC
)) on [PRIMARY]
这是空间索引的 DDL:
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]
我在列上有主键,在[ID]
列上有空间索引GeoLocation
。对于空间索引,我使用镶嵌模式“几何自动网格”。
即使我在数据库中只有几千行,获取最近邻居的查询也很慢。
SELECT top 15 T.ID
FROM dbo.TestT --with(index(IX_SpatialData_Geo))
WHERE T.Geo.Filter(@region) = 1
实际上,通过添加表提示,(强制使用空间索引)查询的性能正在下降而不是提高性能:)
谢谢