mysql varbinary vs varchar [英] mysql varbinary vs varchar

查看:401
本文介绍了mysql varbinary vs varchar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用varchar(255)在mysql中存储关键字。我们面临一个问题,mysql在=中忽略所有尾随空格以进行比较。它确实尊重like比较中的尾随空格,但是如果它有一个UNIQUE索引,它不允许在varchar列中存储相同的单词和不包含尾随空格。

We use varchar(255) for storing "keywords" in mysql. We are facing a problem that mysql ignores all trailing spaces for comparison purposes in "=". It does respect trailing spaces in "like" comparison, but it does not let us store same word with and without trailing spaces in a varchar column if it has a "UNIQUE" index over it.

所以,我们正在考虑切换到varbinary。

So, we are considering switching to varbinary. Can anybody suggest what could be the implications when there are multi-byte characters in column values?

推荐答案

Andomar,

我们使用版本5.0.5。所有mysql版本都会忽略尾随空格以进行比较。从手册:

We use version 5.0.5. All mysql versions ignore trailing spaces for comparison. From the manual:


所有MySQL归类的类型为
PADSPACE。这意味着MySQL中的所有CHAR和
VARCHAR值被比较
,而不考虑任何尾随空格。
这对于所有MySQL版本都是如此,
和它没有什么区别是否
您的版本修剪结尾空格
从VARCHAR值存储之前
他们

All MySQL collations are of type PADSPACE. This means that all CHAR and VARCHAR values in MySQL are compared without regard to any trailing spaces. This is true for all MySQL versions, and it makes no difference whether your version trims trailing spaces from VARCHAR values before storing them

此外,mysql在索引中考虑带有/不含尾随空格的文本:

Moreover mysql considers texts with/without trailing spaces duplicate in indexes:


对于尾随
字符被删除或比较
忽略它们的情况,如果一个列有一个索引
,它需要唯一的值,则将
插入列值不同
只在尾随
字符的数字将导致
重复键错误。例如,如果
表包含'a',则尝试
存储'a'将导致重复键
错误。

For those cases where trailing pad characters are stripped or comparisons ignore them, if a column has an index that requires unique values, inserting into the column values that differ only in number of trailing pad characters will result in a duplicate-key error. For example, if a table contains 'a', an attempt to store 'a ' causes a duplicate-key error.

而且,我们绝对需要一个关键字索引。
所以,我想我们有两个选项:varbinary或text。我们将评估文本的性能,以及varbinary的多字节功能。

And, we absolutely need an index on keywords. So, I guess we have two options: varbinary or text. We shall evaluate the performance of "text", and multibyte functionality for varbinary.

这篇关于mysql varbinary vs varchar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆