0

我试图找到距给定坐标一定距离内的位置。在具有大约 32k 条记录的表上查询大约需要 2 秒 - 这太慢了,imo。

它正在执行聚集索引扫描,这是合乎逻辑的 - 它必须计算每个位置的距离。但是,我仍然认为这应该比这么小的数据集更快。我确实定义了空间索引,但是它没有被使用,如果我强制它查询会失败。

大部分时间(~86%)都花在计算距离的过滤器上——所以我正在寻找一种优化它的方法,我需要一些帮助。

我正在使用的查询是这样的:

SELECT Name
FROM Venue
WHERE (Coordinates.STDistance(geography::STPointFromText('POINT(-113.512245 51.498212)', 4326)) / 1000) <= 100 
4

1 回答 1

0

One old approach is to use a BOX firxt.

From your point, make two points on opposite ends of the box. +R/+R and -R/-R from the center.

Then you can filter - a point has to be in this box AND in the circle you describe.

The box check can run on the index and kills most elements.

Simple school geometry. You draw a rectangular box around the circle you describe.

Your current approach can not use the index because the index does not contain the fields.

ALTERNATIVELY: DRAW A CIRCLE - do not use a distance calculation. Draw a circle. With points.

Or read https://stackoverflow.com/questions/11311363/my-application-is-about-asp-net-using-linq-and-remote-mssql-my-connection-is-be which is the same issue you ask.

于 2012-07-03T13:03:26.210 回答