我有一列地理類型。我已創建AA空間索引,但其不被使用:未使用SQL Server 2008空間索引
declare @geog geography
select @geog = 'POINT (18.12 -33.2)'
select *
from dbo.product WITH(INDEX(IX_Spatial))
where
@geog.STDistance(GeoLocation) > 1000
索引創建這樣的:
CREATE SPATIAL INDEX [IX_Spatial] ON [dbo].[Product]
(
[GeoLocation]
)USING GEOGRAPHY_GRID
WITH (
GRIDS =(LEVEL_1 = MEDIUM,LEVEL_2 = MEDIUM,LEVEL_3 = MEDIUM,LEVEL_4 = MEDIUM),
CELLS_PER_OBJECT = 1024,
PAD_INDEX = OFF, SORT_IN_TEMPDB = OFF,
DROP_EXISTING = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
爲網格線密度分佈的值在各個層次中不故意設置爲中等。如果我查看估計的執行計劃,則不會使用該索引。
[http://blogs.msdn.com/b/isaac/archive/2008/08/29/is-my-spatial-index-being-used.aspx][1]
如果我嘗試將提示添加到查詢優化器
declare @geog geography
select @geog = 'POINT (18.12 -33.2)'
select *
from dbo.product WITH(INDEX(IX_Spatial))
where
@geog.STDistance(GeoLocation) > 1000
我得到這個錯誤:
The query processor could not produce a query plan for a query with a spatial index hint. Reason: Spatial indexes do not support the comparator supplied in the predicate
我的數據庫是在SQL Server 2008中(100)的兼容性級別運行。
。
這解釋了爲什麼使用少於使用索引。謝謝 – 2010-11-11 12:44:11