Created
December 26, 2019 18:11
-
-
Save tameem92/08579a3d2ac690fce395c21bedab4f11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# enable slow query logs in Rails | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
# Get rails to show you the sql that will run | |
User.where(id: 1).to_sql | |
=> "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" = 1" | |
# Get rails to explain the sql query for more detail | |
User.where(id: 1).explain | |
# The explain will tell you which index is being used, and what work happens in the back. | |
=> EXPLAIN for: SELECT "users".* FROM "users" WHERE "users"."id" = $1 [["id", 1]] | |
QUERY PLAN | |
-------------------------------------------------------------------------- | |
Index Scan using users_pkey on users (cost=0.14..8.16 rows=1 width=962) | |
Index Cond: (id = '1'::bigint) | |
(2 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment