アプリのパフォーマンスを向上させるためにインデックスを追加したいと考えています。
追加されたインデックスのパフォーマンスを測定してください。
たとえば、次の表があります。
create_table "classifications", :force => true do |t|
t.integer "app_id"
t.integer "user_id"
t.integer "topic_id"
t.string "targit_type"
t.integer "targit_id"
t.datetime "created_at"
t.datetime "updated_at"
end
ここに3つのインデックスを追加することを考えています:
# Classification
add_index :classifications, :app_id, name: "index_classifications_on_app_id"
add_index :classifications, :user_id, name: "index_classifications_on_user_id"
add_index :classifications, [:target_id, :targit_type], name: "index_classifications_on_targit_id_and_targit_type"
そこで、その変化のパフォーマンスを測定したいと思います。
それを行うための最良の方法はどのようになりますか?Railsコンソールでそれを行う必要がありますか?
>> Agreement.find_by_user_id_and_review_id(User.last.id, Review.last.id)
User Load (14.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
Review Load (4.5ms) SELECT "reviews".* FROM "reviews" ORDER BY "reviews"."id" DESC LIMIT 1
Agreement Load (2.2ms) SELECT "agreements".* FROM "agreements" WHERE "agreements"."user_id" = 2064 AND "agreements"."review_id" = 1557 LIMIT 1