【发布时间】:2014-11-18 10:19:17
【问题描述】:
我有一个数据库表,其中包含存储latitude 和longitude 坐标的列(两者都具有decimal 数据类型)。通过搜索,该表大约有 500k 行。
问题是,如果我搜索半径为 100-200 英里的行,搜索会持续大约 140 秒,这无法投入生产。
堆栈:
- 导轨 4
- MySQL 5.5
- Geokit-rails gem
我想就如何通过地理数据加快搜索速度向您寻求帮助。我应该实现类似于kayak.com 的搜索,在哪里向用户显示一些结果并且搜索仍在后台运行?
提前谢谢你。
编辑:“商店”方案
create_table "stores", force: true do |t|
t.string "store_name"
t.string "address"
t.string "city"
t.string "state"
t.string "county"
t.string "zip_code"
t.decimal "latitude", precision: 10, scale: 6
t.decimal "longitude", precision: 10, scale: 6
end
表上没有索引。我在数据库中有一个类似的表,其中也有 latitude 和 longitude 列,我尝试在它们上添加索引,但搜索的加载时间保持不变。
【问题讨论】:
-
能否请您发布该表的数据库架构?那张表上有索引吗?
-
感谢您的评论,
spickermann。我将表格方案添加到 OP。
标签: mysql ruby-on-rails ruby geolocation geokit