how to get the nearest 100 points from one million data records quickly?

后端 未结 2 436
花落未央
花落未央 2021-01-20 16:42

given one point A, get the nearest 100 points from one million data records

  • database is MySql
  • one million records of latitude and lon
相关标签:
2条回答
  • 2021-01-20 16:53
    1. Setup spatial extensions for your database, if you have not done that already.
    2. Store latitude/longitude of your 1M locations in a geography-type column in the database.
    3. Create a spatial index on that column.
    4. Run a SELECT query with a WHERE clause based on distance between your point of interest and locations in the table. The query will utilize the above index.

    Here is a good article on using spatial extension in MySQL 5.6 for exactly this sort of things.

    0 讨论(0)
  • 2021-01-20 17:09

    http://en.wikipedia.org/wiki/Geohash might be a quick way to speed up the average case, but worst case behaviour would still be bad. The article suggests that you index by geohash and, on a query, retrieve all points in a bounding box that amounts to a geohash prefix. If the bounding box is small and you find a match in it closer than any point outside the bounding box then you have succeeded quickly, but neither of these things might be true.

    0 讨论(0)
提交回复
热议问题