SELECT
WHERE
Buy this Reference Manual in softcover from Barnes & Noble!
BINARY
BLOB
mysql> SELECT "a" = "A"; -> 1 mysql> SELECT BINARY "a" = "A"; -> 0
BINARY string
CAST(string AS BINARY)
SELECT 'A' LIKE UPPER(blob_col) FROM table_name;
Experimenting a bit with "column LIKE constant" on an indexed column shows that it's been optimized as much as one would expect. Thus, having a constant that starts with a non-wildcard gives you a join type of 'range'. It's unclear what happens when there's a leading '_' followed by non-wildcards - will mysql use the sub-ranges for each possible first character, or just search all rows. The latter is what I'd guess, although I might be wrong.
The new BINARY cast is very useful when you need for different purposes the benefits of both case-independence and case- (and diacritic-) dependence. There seem to be two limitations, though. There is no symmetric "NATIONAL" cast, so if you are going to sometimes need to do non-BINARY ("NATIONAL") searches, you have to define the field as non-BINARY in the first place and use the BINARY cast when you need it. Searches using the BINARY cast on a non-BINARY field can also be slow in a big table - presumably because the indexes are non-binary. I can't at the moment see any way of getting the benefit of fast indexed searches in both BINARY and non-BINARY form without duplicating the field.
I needed to put the BINARY keyword after the WHERE keyword for it to have the desired effect with a REGEXP operation. Easy to infer, but not exactly obvious from the example given here.
Add your own comment.