Mysql VARCHAR(X) vs TEXT

一般情况下,我们不太会纠结用Varchar或text数据类型。
比如说,我们要存储邮箱,我们自然会用varchar,不会想到用text。而当我们要存储一段话的时候,选了text,感觉varchar也够用。当然感觉是没有用的,我们可以研究一下。

TEXT and BLOB is stored off the table with the table just having a pointer to the location of the actual storage.

VARCHAR is stored inline with the table. VARCHAR is faster when the size is reasonable, the tradeoff of which would be faster depends upon your data and your hardware, you'd want to benchmark a realworld scenario with your data.

以上引用大致是说:TEXT 和 BLOB 相当于是存储了一个位置指针,这个指针指向一个表结构数据。而VARCHAR是表内级别的数据单元。通过指针去找到表再找到数据,相对而言比表内找到一个数据要效率低些。当然TEXT、BLOB存储量比VARCHAR是要大些。

以下有个清单有助于选定数据该用哪种类型:

VARCHAR(X)

Case: user name, email, country, subject, password

TEXT

Case: messages, emails, comments, formatted text, html, code, images, links

MEDIUMTEXT

Case: large json bodies, short to medium length books, csv strings

LONGTEXT

Case: textbooks, programs, years of logs files, harry potter and the goblet of fire, scientific research logging

参考资料

http://stackoverflow.com/questions/2023481/mysql-large-varchar-vs-text

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值