1
我已經在其中有130萬個記錄全部進行地理編碼的表上設置了一個空間索引。這些值存儲在地理數據類型列中。我遇到的問題是,當我查詢具有空間索引的列時,它仍然非常慢。例如,在一英里範圍內找到所有賬戶大約需要20秒。嘗試查找地理編碼範圍內的所有點時,空間索引較慢。我如何使這個更快?
這裏是運行慢的查詢的例子:
DECLARE @g Geography;
SET @g = (select ci.Geocode from CustomerInformation ci where ci.CIOI = 372658)
DECLARE @region geography = @g.STBuffer(1609.344)
Select top 100 ci.Geocode.STDistance(@g), ci.CIOI
from CustomerInformation ci
where ci.Geocode.Filter(@region) = 1
order by ci.Geocode.STDistance(@g) asc
這裏是我創建索引的語句:
CREATE SPATIAL INDEX [IX_CI_Geocode] ON [dbo].[CustomerInformation]
(
[Geocode]
)USING GEOGRAPHY_GRID
WITH (
GRIDS =(LEVEL_1 = MEDIUM,LEVEL_2 = LOW,LEVEL_3 = LOW,LEVEL_4 = LOW),
CELLS_PER_OBJECT = 128, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
GO
的數據是一個國家的一部分家家戶戶。所以在一英里半徑內,我預計會有1000分或更多。我是否正確編制索引?任何幫助都會很棒。
另一個慢查詢例如:
DECLARE @g Geography;
SET @g = (select ci.Geocode from CustomerInformation ci where ci.CIOI = 372658)
select top(100) CIOI, (ciFinding.Geocode.STDistance(@g)/1609.344) as Distance, ciFinding.Geocode.ToString() --ciFinding.Geocode.STDistance(@g)/1609.344
from CustomerInformation ciFinding
where ciFinding.Geocode.STDistance(@g) is not null and ciFinding.Geocode.STDistance(@g) < 1609.344
order by ciFinding.Geocode.STDistance(@g)