我想添加索引来提高我的应用程序性能。
我想测量添加索引的性能。
例如我有下表:
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
我考虑在这里添加三个索引:
# 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