Tsql 当试图查找地理代码范围内的所有点时,空间索引速度很慢。我怎样才能让它更快?
我已经在一个表上设置了一个空间索引,其中有130万条记录都是地理编码的。这些值存储在地理数据类型列中。我遇到的问题是,当我查询这个有空间索引的列时,速度仍然很慢。例如,找到一英里内的所有帐户大约需要20秒 下面是一个运行缓慢的查询示例:Tsql 当试图查找地理代码范围内的所有点时,空间索引速度很慢。我怎样才能让它更快?,tsql,sql-server-2008,spatial-index,Tsql,Sql Server 2008,Spatial Index,我已经在一个表上设置了一个空间索引,其中有130万条记录都是地理编码的。这些值存储在地理数据类型列中。我遇到的问题是,当我查询这个有空间索引的列时,速度仍然很慢。例如,找到一英里内的所有帐户大约需要20秒 下面是一个运行缓慢的查询示例: DECLARE @g Geography; SET @g = (select ci.Geocode from CustomerInformation ci where ci.CIOI = 372658) DECLARE @region geography =
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
数据是单个州的一部分中的每家每户。所以在一英里半径内,我预计会有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)
您可能需要使用索引提示,即使用Index[Index_NAME],我认为2008 R2可能已经解决了这个问题
Select top 100
ci.Geocode.STDistance(@g), ci.CIOI
from CustomerInformation WITH(INDEX(IX_CI_Geocode))
ci where ci.Geocode.Filter(@region) = 1
order by ci.Geocode.STDistance(@g) asc
您可能需要使用索引提示,即使用Index[Index_NAME],我认为2008 R2可能已经解决了这个问题
Select top 100
ci.Geocode.STDistance(@g), ci.CIOI
from CustomerInformation WITH(INDEX(IX_CI_Geocode))
ci where ci.Geocode.Filter(@region) = 1
order by ci.Geocode.STDistance(@g) asc