I have a sequential scan occurring in my UsersController#create
action.
SELECT ? AS one FROM "users" WHERE (LOWER("users"."username") = LOWER(?) AND "users"."id" != ?) LIMIT ?
Explain plan
1 Query planLimit (cost=0.00..3.35 rows=1 width=0)
2 Query plan-> Seq Scan on users (cost=0.00..3.35 rows=1 width=0)
3 Query planFilter: ?
I am fairly positive this arises from the following model validation:
validates :username, uniqueness: { case_sensitive: false }
Should I be creating an index against this express? And if so, what's the proper way to do this in Rails 4?