我在这个查询上得到一个随机/间歇性的 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 Profiler 中捕获它,它连续显示查询和超过 188 条语句,这真的很令人困惑,因为当我在 SSMS 中运行它时,它只显示 1 次执行,但在应用程序中运行会生成 188 条子语句。: