Which collation is preferred when sorting is not required?
I have a table e.g.:
create table T1(Id int primary key auto_increment, Value text)
Value
is used to store "textual" data but rows are never sorted according to the 开发者_如何转开发Value
column.
Which collation should be prefered for Value
?
Would utf8mb4_bin
be a better choice or utf8mb4_general_ci
?
That looks fine. I certainly wouldn't use a case-insensitive collation if it wasn't needed (as per your case) since it may result in slower queries (though I doubt it would be used for non-textual fields anyway).
You should keep in mind, however, that collation is not just for sorting, but for selection as well (e.g., the where
clause). If you're only going to retrieve rows based on columns other than Value
, that shouldn't matter.
In any case, I'm actually not a big fan of case-insensitive collations being done by the database itself, since I'd rather keep the database running as blindingly fast as possible, and use my own methods to handle case issues (such as an extra indexed column holding lower-cased last names, and updated with insert/update triggers to maintain consistency with the rest of the row).
Basically, I'm a Luddite :-) but nobody ever complains about how big their databases are, only about how slow.
精彩评论