sql - varchar(255) v tinyblob v tinytext

标签 sql mysql database-design

我的附带问题是 tinyblob 和 tinytext 之间真的有什么区别吗?

相信我真正的问题是什么原因,如果有的话,我会选择 varchar(255) 而不是 tinyblob 或 tinytext?

最佳答案

主要是 storage requirements和内存处理/速度:

In the following table, M represents the declared column length in characters for nonbinary string types and bytes for binary string types. L represents the actual length in bytes of a given string value.

VARCHAR(M), VARBINARY(M):
L + 1 bytes if column values require 0 – 255 bytes,
L + 2 bytes if values may require more than 255 bytes

TINYBLOB, TINYTEXT:
L + 1 bytes, where L < 28

此外,请参阅 this帖子:

For each table in use, MySQL allocates memory for 4 rows. For each of these rows CHAR(X)/VARCHAR(X) column takes up the X characters.

A TEXT/BLOB on the other hand is represented by a 8 byte pointer + a 1-4 byte length (depending on the BLOB/TEXT type). The BLOB/TEXT is allocated dynamicly on use. This will use less memory, but in some cases it may fragment your memory in the long run.

编辑:顺便说一句,blob 存储二进制数据而文本存储 ASCII,这是 TINYBLOB 和 TINYTEXT 之间的唯一区别。

关于sql - varchar(255) v tinyblob v tinytext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/143933/

相关文章:

php - is_unique 在 codeigniter 中用于编辑功能

sql - 在 Postgres JOIN 查询中区分 null 和 empty

python - 切片后订购 Django QuerySet

mysql - 仅当两个或多个记录具有相同值时才连接两个表并分组

mysql - 是否可以只对列应用一个唯一约束,同时定义其他约束?

mysql - COUNT() 是否需要 GROUP BY?

MySQL递归程序删除一条记录

PHP - 计算多少天前

mysql - 用于存储表达式及其在文本中出现的数据库模型

MySQL 匹配同一表中的列