Mysql 5 中列级别的 CHARSET

发布于 2024-10-08 13:13:16 字数 304 浏览 0 评论 0原文

我的应用程序有一个表,其中有两列需要 utf8,其他列是拉丁文。根据定义,拉丁字符不包含非拉丁字符,utf8 字符可能包含也可能不包含 utf8 字符。其中一个 utf8 列已建立索引,而其他列则未建立索引。

我有三个问题:

在列级别混合字符集是一种好的做法吗?

如果(此表上的)一行仅包含拉丁字符而不包含 utf8 字符,数据存储和索引大小会受到怎样的影响?换句话说,utf8 列数据/索引大小与拉丁语相同,但不存储任何 utf8 文本。

从数量上讲,相对于拉丁语,数据和索引存储对 utf8 列有何影响?

谢谢

My app has a table that has two columns needing utf8 and others are latin. Latin ones does not contain non-latin characters by definition and utf8 ones may or may not contain utf8 ones. One utf8 column is indexed and other is not.

I have three questions:

Is mixing charsets on a column level a good practice?

If a row (on this table) contains only latin chars and no utf8 chars how are data storage and index size affected? Put another way, is a utf8 column data/index size same as latin without storing any utf8 text.

Quantitively how are data and index storage affected on utf8 columns with respect to latin?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

宛菡 2024-10-15 13:13:16

UTF-8 是一种可变长度编码。 ASCII 集内的字符将像 latin1 一样用一个字节进行编码;超出此范围的字符将使用最多四个字节进行编码。由 ASCII 字符组成的字符串在 UTF8 和 latin1 中具有相同的长度。

在列级别混合字符集是一个好的做法吗?

我从来没有这样做过,并且倾向于拒绝,因为它不必要地使数据库模式变得复杂。虽然数据库引擎应该能够很好地处理它,但出于存储考虑,我不会使用混合字符集。节省的费用充其量也是微乎其微的。

我能想到的混合字符集的唯一有效原因是对特定排序顺序和/或区分大小写/重音/不敏感的搜索使用不同的排序规则。

UTF-8 is a variable length encoding. Characters inside the ASCII set will be encoded with one byte as in latin1; characters beyond that will be encoded using up to four bytes. A string consisting of ASCII characters will have the same length in UTF8 and latin1.

Is mixing charsets on a column level a good practice?

I have never done this, and would tend to say no, as it complicates the database schema unnecessarily. While the database engine should be able to deal with it fine, I would not use mixed charsets out of storage considerations. The savings will be minimal at best.

The only valid reason to mix charsets that I can think of is the use of different collations for a specific sort order and/or case/accent sensitive/insensitive searching.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文