Whats the fastest way to lookup big tables for points within radius MySQL (latitude longitude)(为 MySQL 半径内的点查找大表的最快方法是什么(经度纬度))
问题描述
目前我有几个表有 100k+ 行.我正在尝试查找如下数据.
SELECT*, SQRT(POW(69.1 * (latitude - '49.1044302'), 2) + POW(69.1 * ('-122.801094' - longitude) * COS(latitude/57.3), 2)) AS距离从站有距离<5ORDER BY 距离限制 100但目前这种方法会因高负载而变慢.有些查询需要 20 多秒才能完成.
如果有人知道任何更好的优化方法就太好了.
首先,如果你有大量的地理空间数据,你应该使用 mysql 的地理空间扩展而不是这样的计算.然后您可以创建空间索引,这将加快很多查询,您不必像上面那样编写冗长的查询.
使用与 ST_Distance 或创建具有感兴趣半径的几何体以及 ST_within 可能会给您带来良好的结果,并且可能比当前快得多.然而,实现此目标的最佳和最快方法是 ST_Dwithin 尚未在 mysql 中实现.>
Currently I have a few tables with 100k+ rows. I am trying to lookup the data like follows.
SELECT
*, SQRT(POW(69.1 * (latitude - '49.1044302'), 2) + POW(69.1 * ('-122.801094' - longitude) * COS(latitude / 57.3), 2)) AS distance
FROM stops
HAVING distance < 5
ORDER BY distance limit 100
But currently this method slows with high load. Some queries are taking 20+ seconds to complete.
If anyone knows any better ways to optimize this would be great.
Well first of all if you have a lot of geospatial data, you should be using mysql's geospatial extensions rather than calculations like this. You can then create spatial indexes that would speed up many queries and you don't have to write long drawn out queries like the one above.
Using a comparision with ST_Distance or creating a geometry with the radius of interest along with ST_within might give you good results and could be a lot faster than the current. However the best and fastest way to achieve this, ST_Dwithin isn't implemented yet in mysql.
这篇关于为 MySQL 半径内的点查找大表的最快方法是什么(经度纬度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为 MySQL 半径内的点查找大表的最快方法是什么(经度纬度)
基础教程推荐
- 无法解决整理冲突 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
