This project is archived and is in readonly mode.

#2503 open
Dave Grijalva

validates_uniqueness_of is horribly inefficient in mysql

Reported by Dave Grijalva | April 16th, 2009 @ 12:09 AM | in 3.x

mysql is case insensitive by default. for case insensitive comparisions, the following is efficient.

WHERE users.username = 'myUsername'

validates_uniqueness_of currently generates

WHERE LOWER(users.username) = BINARY 'myusername'

this is redundant and completely clobbers performance. If you have a unique index on the column (and you should, because validates_uniqueness_of cannot be trusted), you don't get any of the benefit of the index because the system has to transform the column.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Tickets have moved to Github

The new ticket tracker is available at https://github.com/rails/rails/issues

Shared Ticket Bins

Tags

Referenced by

Pages