加速复杂的查询(索引或其他技术)

时间:2015-11-28 19:17:16

标签: sql ruby-on-rails postgresql indexing

我试图加快复杂的轨道查询,基本上搜索场地上的位置。该位置可以是以太名称,城市,县或国家。

我尝试添加索引,但我认为我没有正确完成此操作。

这是我的场地架构:

  create_table "venues", force: :cascade do |t|
    t.string   "name"
    t.string   "address"
    t.string   "postcode"
    t.string   "city"
    t.string   "country"
    t.datetime "created_at",     null: false
    t.datetime "updated_at",     null: false
    t.string   "postplace"
    t.string   "map_address"
    t.decimal  "latitude"
    t.decimal  "longitude"
    t.string   "slug"
    t.text     "description"
    t.string   "website"
    t.integer  "import_id"
    t.string   "postal_address"
    t.string   "email"
    t.string   "county"
    t.string   "region"
    t.string   "country_name"
  end

  add_index "venues", ["country_name"], name: "index_venues_on_country_name", using: :btree
  add_index "venues", ["import_id"], name: "index_venues_on_import_id", using: :btree
  add_index "venues", ["name", "city", "county", "country"], name: "location", using: :btree
  add_index "venues", ["slug"], name: "index_venues_on_slug", unique: true, using: :btree

这是我查询的相关部分:

  def filter_on_location
    @events = events.
      joins(:venue).where(
        "venues.city ILIKE :location
        OR venues.county ILIKE :location
        OR venues.country ILIKE :location
        OR venues.name = :location",
        location: params[:location])
  end

任何提示都表示赞赏!

0 个答案:

没有答案