Indexes can be used only when the expression's collation matches that on the indexed column.
If the expression's COERCIBILITY
is lower than that of the column (that is 2
), the column's collation is casted to that of the expression, and the index is not used.
Normally, literals have COERCIBILITY
of 4
and user variables that of 3
, so this should be not a problem.
However, if you mix different collations in a JOIN
or UNION
, the cast order is not guaranteed.
In this case you should provide explicit collation to the column your are casting (most probably, you want to cast latin1
to UTF8
), and this should be the collation of the column you are casting to:
SELECT *
FROM utf_table
JOIN latin_table
ON utf_column = latin_column COLLATE UTF8_GENERAL_CI