すべてジオコーディングされた130万件のレコードを含むテーブルに空間インデックスを設定しました。これらの値は、地理データタイプの列に格納されます。私が抱えている問題は、空間インデックスを持つこの列をクエリすると、まだ本当に遅いということです。たとえば、1マイル以内のすべてのアカウントを見つけるのに約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
これが私のcreateindexステートメントです:
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
データは、単一の州の一部にあるすべての家です。したがって、半径1マイルでは、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)