我有两组来自卫星数据的地球测量值,每组都有时间场(平均朱利安日期的 mjd)和地理位置(GeoPoint,空间),我正在寻找两组之间的巧合,以便它们的时间匹配阈值3 小时(或 0.125 天),它们之间的距离在 200 公里以内。
我已经为表和空间表上的 mjd 字段创建了索引。
当我刚刚加入时间限制时,数据库会在 8 秒内计算 100,000 个匹配项,并计算该时间内所有 100,000 个匹配项的距离。查询如下所示:
select top 100000 h.Time, m.Time, h.GeoPoint.STDistance(m.GeoPoint)/1000.0
from L2V5.dbo.header h join L2.dbo.MLS_Header m
on h.mjd between m.mjd-.125 and m.mjd+.125
option( table hint ( h, index(ix_MJD) ), table hint( m, index(ix_MJD) ) )
Run Code Online (Sandbox Code Playgroud)
并且执行的计划是:
排序后,有 9 个距离在 200 公里以下,因此存在匹配项。问题是,当我添加距离约束并运行它时,
select top 10 h.Time, m.Time, h.GeoPoint.STDistance(m.GeoPoint)/1000.0
from L2V5.dbo.header h join L2.dbo.MLS_Header m
on h.mjd between m.mjd-.125 and m.mjd+.125
and h.GeoPoint.STDistance(m.GeoPoint)<200000
option( table hint ( h, index(ix_MJD) …
Run Code Online (Sandbox Code Playgroud)