dongyanju1094 2012-04-03 06:57
浏览 142
已采纳

距离计算是更快的mongodb或mysql

I am little bit confused about following problem & their solutions: i have 2 tables users & userfriends having following structure

users
userid         lat          long


userfriends
    userid         friendid

so in users table i have lat & long of all the users & in userfriends i have list of friends for each user. Now i want to calculate nearby users (distance) so my friend told me to use mongodb which have fast performance. But i found another function which i can use in stored procedure in mysql

function distance($lat1, $lon1, $lat2, $lon2, $unit) { 

  $theta = $lon1 - $lon2; 
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
  $dist = acos($dist); 
  $dist = rad2deg($dist); 
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);

  if ($unit == "K") {
    return ($miles * 1.609344); 
  } else if ($unit == "N") {
      return ($miles * 0.8684);
    } else {
        return $miles;
      }
}

So basically i want my distance calculation faster & quick. So can somebody tell me am i correct in my way or i need to send needed data (lat & long of users friends) to mongodb & calculate & mongodb will return results to my database (MySQL)?

  • 写回答

1条回答 默认 最新

  • dtihe8614 2012-04-03 09:15
    关注

    Both MySQL and MongoDB support geospatial indexing. IME, NoSQL databases have huge performance advantages when dealing with selecting individual records, but offer less of a performance benefit (still usually faster) compared with a relational database when dealing with range queries - YMMV.

    There are other very fundamental differences - which are well covered elsewhere.

    You really want to spend a lot of time reading the linked documents - the method you describe will be phenomonally innefficient.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容