From bec751c4fd066494f21c689312f3330724b27087 Mon Sep 17 00:00:00 2001 From: RJ Osborne Date: Sat, 23 May 2015 08:48:13 -0400 Subject: [PATCH] Added indexes on the frequent queries. The problem is still too many queries. --- db/migrate/20150523121319_introduce_indexes.rb | 10 ++++++++++ db/schema.rb | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20150523121319_introduce_indexes.rb diff --git a/db/migrate/20150523121319_introduce_indexes.rb b/db/migrate/20150523121319_introduce_indexes.rb new file mode 100644 index 0000000..ff24411 --- /dev/null +++ b/db/migrate/20150523121319_introduce_indexes.rb @@ -0,0 +1,10 @@ +class IntroduceIndexes < ActiveRecord::Migration + def change + add_index :weights, :tournament_id + add_index :schools, :tournament_id + add_index :mats, :tournament_id + add_index :matches, :tournament_id + add_index :matches, [:w1, :w2], :unique => true + add_index :wrestlers, :weight_id + end +end diff --git a/db/schema.rb b/db/schema.rb index d9d5f13..ffedbe8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150517075923) do +ActiveRecord::Schema.define(version: 20150523121319) do create_table "matches", force: :cascade do |t| t.integer "w1" @@ -34,6 +34,9 @@ ActiveRecord::Schema.define(version: 20150517075923) do t.string "loser2_name" end + add_index "matches", ["tournament_id"], name: "index_matches_on_tournament_id" + add_index "matches", ["w1", "w2"], name: "index_matches_on_w1_and_w2", unique: true + create_table "mats", force: :cascade do |t| t.string "name" t.integer "tournament_id" @@ -41,6 +44,8 @@ ActiveRecord::Schema.define(version: 20150517075923) do t.datetime "updated_at" end + add_index "mats", ["tournament_id"], name: "index_mats_on_tournament_id" + create_table "schools", force: :cascade do |t| t.string "name" t.datetime "created_at" @@ -48,6 +53,8 @@ ActiveRecord::Schema.define(version: 20150517075923) do t.integer "tournament_id" end + add_index "schools", ["tournament_id"], name: "index_schools_on_tournament_id" + create_table "tournaments", force: :cascade do |t| t.string "name" t.string "address" @@ -83,6 +90,8 @@ ActiveRecord::Schema.define(version: 20150517075923) do t.integer "tournament_id" end + add_index "weights", ["tournament_id"], name: "index_weights_on_tournament_id" + create_table "wrestlers", force: :cascade do |t| t.string "name" t.integer "school_id" @@ -97,4 +106,6 @@ ActiveRecord::Schema.define(version: 20150517075923) do t.boolean "extra" end + add_index "wrestlers", ["weight_id"], name: "index_wrestlers_on_weight_id" + end