我有一个包含大约500个点的表,我正在寻找容差范围内的重复项.这需要不到一秒钟,给我500行.大多数的距离为零,因为它给出了相同的点(PointA = PointB)
DECLARE @TOL AS REAL
SET @TOL = 0.05
SELECT
PointA.ObjectId as ObjectIDa,
PointA.Name as PTNameA,
PointA.[Description] as PTdescA,
PointB.ObjectId as ObjectIDb,
PointB.Name as PTNameB,
PointB.[Description] as PTdescB,
ROUND(PointA.Geometry.STDistance(PointB.Geometry),3) DIST
FROM CadData.Survey.SurveyPoint PointA
JOIN [CadData].Survey.SurveyPoint PointB
ON PointA.Geometry.STDistance(PointB.Geometry) < @TOL
-- AND
-- PointA.ObjectId <> PointB.ObjectID
ORDER BY ObjectIDa
Run Code Online (Sandbox Code Playgroud)
如果我使用靠近底部的注释掉的行,我会得到14行,但执行时间最长可达14秒.在我的积分表扩大到数十万之前,这笔交易并不是那么大.
如果答案已经存在,我会提前道歉.我确实看了,但是新的我迷失了阅读的帖子,这些都是我的头脑.
ADDENDUM:ObjectID是一个bigint和表的PK,所以我意识到我可以将语句更改为
AND PointA.ObjectID > PointB.ObjectID
Run Code Online (Sandbox Code Playgroud)
现在这需要一半的时间,并给我一半的结果(7秒内7行).我现在不会重复(因为在第4点接近第8点,然后第8点接近第4点).然而,性能仍然令我担忧,因为该表将非常大,因此任何性能问题都将成为问题.
附录2:如下所示更改JOIN和AND(或建议的WHERE)的顺序也没有区别.
DECLARE @TOL AS REAL
SET @TOL = 0.05
SELECT
PointA.ObjectId as ObjectIDa,
PointA.Name as PTNameA,
PointA.[Description] as PTdescA,
PointB.ObjectId as …Run Code Online (Sandbox Code Playgroud)