我想添加索引來提高我的應用性能。如何測試在Rails控制檯中添加索引性能?
我想喲測量添加索引的性能。
,比如我有如下表:
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