MySQL:大型VARCHAR与TEXT? [英] MySQL: Large VARCHAR vs. TEXT?

查看:293
本文介绍了MySQL:大型VARCHAR与TEXT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL中有一个消息表,该表记录了用户之间的消息.除了典型的ID和消息类型(所有整数类型)之外,我还需要将实际消息文本另存为VARCHAR或TEXT.我将前端限制设置为3000个字符,这意味着消息插入数据库的时间绝不会超过此时间.

I've got a messages table in MySQL which records messages between users. Apart from the typical ids and message types (all integer types) I need to save the actual message text as either VARCHAR or TEXT. I'm setting a front-end limit of 3000 characters which means the messages would never be inserted into the db as longer than this.

是否有使用VARCHAR(3000)或TEXT的理由?只是编写VARCHAR(3000)有点违反直觉的事情.我曾经在Stack Overflow上浏览过其他类似的文章,但是最好获得特定于这种常见消息存储类型的视图.

Is there a rationale for going with either VARCHAR(3000) or TEXT? There's something about just writing VARCHAR(3000) that feels somewhat counter-intuitive. I've been through other similar posts on Stack Overflow but would be good to get views specific to this type of common message storing.

推荐答案

  • TEXTBLOB 可以在表外存储,而该表仅具有指向实际存储位置的指针.它的存储位置取决于许多因素,例如数据大小,列大小,row_format和MySQL版本.

    • TEXT and BLOB may by stored off the table with the table just having a pointer to the location of the actual storage. Where it is stored depends on lots of things like data size, columns size, row_format, and MySQL version.

      VARCHAR与表内联存储. VARCHAR在大小合理的情况下会更快,其折衷会更快,这取决于您的数据和硬件,您希望使用数据对实际场景进行基准测试.

      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 real-world scenario with your data.

      这篇关于MySQL:大型VARCHAR与TEXT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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