如何在 SQL CE 中有效搜索作为路口的附近地理节点?

发布于 2025-01-03 12:44:29 字数 1089 浏览 4 评论 0原文

我有以下查询:

var nodes = DB.Nodes
              .Where(x =>    x.Lon > 486400
                          && x.Lon < 486600
                          && x.Lat > 5025100
                          && x.Lat < 5025300)
              .Join(DB.RoadNodes, x => x.Id, y => y.NodeId, (x, y) => x);

这会搜索特定位置附近的 DB.Nodes 中的所有节点,然后通过与 DB.RoadNodes 连接来检查该节点是否是路口。代码>;然而,这需要几秒钟的时间,速度很慢。

看起来我必须在这里做两件事:

  1. 优化 Where 部分,它本身需要 ~5 秒,我听说过一些关于 Spatial 的事情?

  2. 优化Join部分,它本身需要剩余~15秒,我需要一个索引,对吗?

所以我对此有两个问题:

  1. 如何在 SQL Server Compact Edition 中进行空间存储和搜索?

    如果不受支持,我该如何解决此问题?

  2. 我需要为哪些列建立索引才能使该查询充分发挥作用?

    似乎对 RoadNodes 的 NodeId 建立索引并没有真正改善查询。

请注意,我仅限于 SQL CE,因为我打算在 Windows Phone 7 上运行它。

另外,我需要从中获取 Unique(),这使得查询稍微长一些,但我我猜如果查询本身运行得很快,那应该不是问题。只是他 join 引入了双重结果,或者我应该以其他方式进行 Join 吗?

I have the following query:

var nodes = DB.Nodes
              .Where(x =>    x.Lon > 486400
                          && x.Lon < 486600
                          && x.Lat > 5025100
                          && x.Lat < 5025300)
              .Join(DB.RoadNodes, x => x.Id, y => y.NodeId, (x, y) => x);

This searches all the nodes in DB.Nodes near a certain location, then it checks whether the node is a road junction by taking a join with DB.RoadNodes; however, this takes several seconds which is slow.

It looks like I have to do two things here:

  1. Optimize the Where part which takes ~5 seconds on its own, I heard something about Spatial?

  2. Optimize the Join part which takes a remaining ~15 seconds on its own, I need an index, right?

So I have two questions about this:

  1. How can I do spatial storage and searching in SQL Server Compact Edition?

    If this is unsupported, how do I work around this issue?

  2. Which columns do I need to index for this query to work sufficiently?

    It seems like indexing the NodeId of RoadNodes doesn't really improve the query.

Please note that I am restricted to SQL CE as I intend to run this on a Windows Phone 7.

Also node that I need to take an Unique() from that, which makes the query slightly longer but I guess that shouldn't be an issue if the query itself runs fast. It's just that he join introduces double results, or should I do the Join in another way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文