1

我在此查詢上得到一個隨機/間歇性的SQL超時,看起來像從一個簡單的查詢中產生大量的處理。這是正確的行爲?SQL超時地理查詢

我有這樣一個簡單的存儲過程:

CREATE PROCEDURE [dbo].[FindClosestXNearCoordinates] 
     @latitude decimal, 
     @longitude decimal 
    AS 
BEGIN 

SET NOCOUNT ON; 
declare @emptyGUID uniqueidentifier 
set @emptyGUID = cast(cast(0 as binary) as uniqueidentifier) 
declare @radiusInMeters float 
set @radiusInMeters = 3500 * 1609.344 
declare @coordinatePoint as Geography 
SET @coordinatePoint = geography::STGeomFromText('POINT(' + CAST(@longitude AS VARCHAR(20)) + ' ' + CAST(@latitude AS VARCHAR(20)) + ')', 4326) 
declare @coordinateRadius as Geography 
set @coordinateRadius = @coordinatePoint.STBuffer(@radiusInMeters); 


select top 1 [b].[BaseId], [b].[Code], [b].[Name], [b].[Location], [b].[TerritoryId], [b].[Latitude], [b].[Longitude] 
from  XTable b 
where  (b.GeoLocation.STIntersects(@coordinateRadius) = 1) 
order by b.GeoLocation.STDistance(@coordinatePoint) asc 

END 

我捕捉到它在SQL事件探查器,它顯示的查詢和超過188陳述成一排,這是因爲當我在SSMS運行這真的令人困惑它只顯示1個執行,但在應用程序中運行會生成188個子語句。:

+0

[link] http://i.imgur.com/4Bk9y.jpg這裏是配置文件轉儲。 – ExtremeCoder123

回答

0

首先是SQL事件探查器。由於Spatial類型對於SQL Server來說有點特殊,它們會產生額外的處理。它爲相同的TSQL語句多次註冊SP:Starting和SP:已完成的條目,因爲它只能在TSQL級別報告操作。你只需要忍受這一點。它是在SQL Server的同一2012

關於您的查詢超時,我建議用更基本的測試替換STIntersect(),使病情

where (b.longitude between @[email protected] and @[email protected]) 
    and (b.latitude between @[email protected] and @[email protected]) 
order by b.GeoLocation.STDistance(@coordinatePoint) asc 

而且關鍵是要弄清楚通過將儀表轉換爲十進制值來提供合適的@xdelta。目前轉換讓我感到遺憾,但Google是你的朋友。如果您真的需要,您甚至可以添加STIntersect(緩衝區)。

+0

這非常棒,謝謝!我想這是地理我還沒有測試過2012年我會發布更新。 – ExtremeCoder123