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

后端 未结 2 437
花落未央
花落未央 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.

提交回复
热议问题