This bug is similar to http://bugs.mysql.com/bug.php?id=5134
Note, the patch for MySQL bug#5134 fixed only a particular case of the problem when the BINARY keyword is used. The problem is in fact more general.
correctly returns one row:
Now if I add an extra part into the condition:
it returns two rows:
The expected result is to return one row in both cases.
The problem happens because "AND a='a' COLLATE latin1_bin" gets erroneously replaced to "AND 'a'='a' COLLATE latin1_bin" which is further evaluates to TRUE and gets removed from the WHERE condition. So, the query gets rewritten to:
The method which actually replaces the field to the constant is Item_field::equal_fields_propagator() in item.cc.
This condition is not strict enough:
It should also take into account the collations of the two operations that the field "a" appears in.