mysql lat long_Mysql cpu用法增加排序lat lon距离最近点

问题是:为什么mysql的cpu使用率达到300% - > 当我在我的脚本php中添加此查询时,400%?

the question is: Why mysql's cpu usage goes to 300% -》 400% when i add this query in my script php ?

我想从坐标点(MYLAT,MYLON)找到某个类别(cat\_id)的最近兴趣点(poi id)

I want to find the nearest Point of intereset (poi\_id) of certain category (cat\_id) from a coordinates point (MYLAT, MYLON)

POI (poi)表:

TABLE of **POI** (poi):

| poi_id | name | city_id | lat | lon |

**相关性表**(corr):

TABLE of **correlations** (corr):

| cat_id | poi_id | city_id |

表**城市**(城市)

TABLE of **CITIES** (city)

| city_id | name |

**脚本:**

**SCRIPT:**

$ lat = **MYLAT** ; //我的起点的纬度

$lat = **MYLAT**; // Latitude of my starting point

$ lon = **MYLON** ; //我的起点的经度

$lon = **MYLON**; // Longitude of my starting point

**包围框**:

**Bounding box**:

$ lon1 = $ lon - ($ dist / abs(cos(rad2deg($ lat))\* 60 \* 1.1515));

$lon1 = $lon - ($dist/abs(cos(rad2deg($lat)) \* 60 \* 1.1515));

$ lon2 = $ lon +($ dist / abs(cos(rad2deg($ lat))\* 60 \* 1.1515));

$lon2 = $lon + ($dist/abs(cos(rad2deg($lat)) \* 60 \* 1.1515));

$ lat1 = $ lat - ($ dist / 60 \* 1.1515);

$lat1 = $lat - ($dist/ 60 \* 1.1515);

$ lat2 = $ lat +($ dist / 60 \* 1.1515);

$lat2 = $lat + ($dist/ 60 \* 1.1515);

当我添加此查询时,CPU使用率变得疯狂:

When I add this query the CPU usage goes insane:

SELECT a.poi_id,a.name,a.city_id,g.name,a.lat, a.lon,

((ACOS(SIN($lat * PI() / 180) * SIN(a.lat * PI() / 180) +

COS($lat * PI() / 180) * COS(a.lat * PI() / 180) *

COS(($lon - a.lon) * PI() / 180)) * 180 / PI()) * 69.09) AS distance

FROM poi a JOIN corr c on a.poi_id = c.poi_id JOIN city g on c.city_id = g.city_id

WHERE a.lon 》 $lon1 and a.lon 《 $lon2

AND a.lat 》 $lat1 and a.lat 《 $lat2

AND c.cat_id = $cat_id

HAVING distance 《 $dist

ORDER BY distance

LIMIT 20

+----+-------------+-------+--------+----------------------------------+---------+---------+--------------------+------+-----------------------------+

| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

+----+-------------+-------+--------+----------------------------------+---------+---------+--------------------+------+-----------------------------+

| 1 | SIMPLE | a | range | poi_id,lat,lon,lat_2 | lat_2 | 14 | NULL | 6924 | Using where; Using filesort |

| 1 | SIMPLE | c | eq_ref | city_id_2,cat_id,poi_id,city_id | cat_id | 5 | const,a.poi_id | 1 | |

| 1 | SIMPLE | g | eq_ref | PRIMARY | PRIMARY | 4 | c.city_id | 1 | Using where |

+----+-------------+-------+--------+----------------------------------+---------+---------+--------------------+------+-----------------------------+

mysql》 show profile;

+----------------------+----------+

| Status | Duration |

+----------------------+----------+

| starting | 0.000138 |

| checking permissions | 0.000010 |

| checking permissions | 0.000006 |

| checking permissions | 0.000008 |

| Opening tables | 0.000028 |

| System lock | 0.000015 |

| init | 0.000043 |

| optimizing | 0.000023 |

| statistics | 0.000221 |

| preparing | 0.000024 |

| Creating tmp table | 0.000029 |

| executing | 0.000005 |

| Copying to tmp table | 0.174197 |

| Sorting result | 0.000066 |

| Sending data | 0.000065 |

| end | 0.000006 |

| removing tmp table | 0.000010 |

| end | 0.000006 |

| query end | 0.000005 |

| closing tables | 0.000011 |

| freeing items | 0.000077 |

| logging slow query | 0.000005 |

| cleaning up | 0.000006 |

+----------------------+----------+

23 rows in set (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值