当不需要排序时首选哪种排序规则?
我有一个表,例如:
create table T1(Id int primary key auto_increment, Value text)
Value
用于存储“文本”数据,但行从不根据Value
列排序。
Value
应该首选哪种排序规则?
utf8mb4_bin
是更好的选择还是 utf8mb4_general_ci
更好?
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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来不错。如果不需要(根据您的情况),我当然不会使用不区分大小写的排序规则,因为它可能导致查询速度变慢(尽管我怀疑它会无论如何都可以用于非文本字段)。
但是,您应该记住,排序规则不仅用于排序,还用于选择(例如,
where
子句)。如果您只想根据Value
以外的列检索行,那应该没有关系。无论如何,我实际上不太喜欢由数据库本身完成的不区分大小写的排序规则,因为我宁愿让数据库尽可能快地运行,并使用我自己的排序规则处理大小写问题的方法(例如保存小写姓氏的额外索引列,并使用插入/更新触发器进行更新以保持与行的其余部分的一致性)。
基本上,我是一个勒德分子:-),但没有人抱怨他们的数据库有多大,只有慢。
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 thanValue
, 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.