In a Vote model, there is a validation:
validates_uniqueness_of :topic_id, :scope => [:user_id]
It is translated to the following SQL in development log:
SELECT 1 AS one FROM `votes` WHERE (`votes`.`topic_id` = BINARY 2 AND `votes`.`user_id` = 1) LIMIT 1
Where there is a BINARY in front of 2 (topic_id)? And, what does it mean?
It is an efficient way of comparing byte to byte instead of character to character
example
Suppose if your have a database table called
productsrecord which hasvin_number(some column name) with record with value ofvin_numbersay123456Now If you ran the this
and
Both will result the same result
Notice the space in the second select
But with binary the comparison
or
A byte by byte match is done as against character to character
so the first one would result in
validresultand
the second one would no result
Here the link that will further help you on this