【发布时间】:2011-04-27 04:43:03
【问题描述】:
我有一个 SQL 查询,它试图查找某些县的所有社区。p>
当我使用 SQL Sentry Plan Explorer 来可视化查询时(IMO,比 MS SSMS 提供的工具好一点),它突出显示了一个执行速度非常慢的部分:-
完整计划
放大....
详情
SQL 脚本:
-- Update which Neighbourhoods are in these Counties.
INSERT INTO @NeighbourhoodCounties (NeighbourhoodId, CountyId)
SELECT SubQuery.NeighbourhoodId, SubQuery.CountyId
FROM (
SELECT e.LocationId AS NeighbourhoodId, b.LocationId AS CountyId,
c.OriginalBoundary.STArea() AS CountyArea,
c.OriginalBoundary.STIntersection(d.OriginalBoundary).STArea() AS IntersectionArea
FROM @CountyIds a
INNER JOIN [dbo].[Counties] b ON a.Id = b.LocationId
INNER JOIN [dbo].[GeographyBoundaries] c ON b.LocationId = c.LocationId
INNER JOIN [dbo].[GeographyBoundaries] d ON c.OriginalBoundary.STIntersects(d.OriginalBoundary) = 1
INNER JOIN [dbo].[Neighbourhoods] e ON d.LocationId = e.LocationId
) SubQuery
WHERE (SubQuery.IntersectionArea / SubQuery.CountyArea) * 100 > 5 -- a Neighbourhood has to be 5% or more to be considered 'Inside'
谁能帮助解释这个查询?所有这些数字是什么意思?如何使用这些数字来帮助诊断和改进我的查询?
I tried to make an indexed view on the spatial table 但惨败。
谁能帮忙?
【问题讨论】:
-
是慢还是不喜欢64.5%?
标签: performance sql-server-2008