Does the chosen collation matters in this case?
I've a field of type char(1)
in my MySQL table which basically can have only values m or f. Its current collation is set to ut8_unicode_ci. I was thinking whether I should or should not change the collation to something 开发者_如何转开发simpler like latin because the full set of utf8 chars is never used - only the chars m or f. Would that change something?
I doubt that it will make any measurable difference, but if m
and f
are the only possible values, then utf8_bin
should produce exactly the same results as utf8_unicode_ci
(or most other collation algorithms for that matter). And since that collation does a simple binary comparison it's bound to be the fastest one around.
Collation is the rule that defines how the characters are supposed to be ordered. Imagine an alphabet sequence - A is 1st letter and Z is the last letter (in English). Collation is the rule that says that A
is first and Z
is last and it also helps define how characters are compared. In short - collation has nothing to do with anything in your case.
What you should do is set that field to tinyint, until MySQL comes up with boolean types later on. That way you'll bypass any charset issues that might arise at any point, although in your example they're not really what matters.
精彩评论