MySQL: Large VARCHAR vs. TEXT?(MySQL:大 VARCHAR 与文本?)
问题描述
我在 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.
推荐答案
TEXT和BLOB可以存储在表外,而表只有一个指向实际存储位置的指针.它的存储位置取决于很多因素,例如数据大小、列大小、row_format 和 MySQL 版本.TEXTandBLOBmay 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在大小合理时更快,权衡更快取决于您的数据和您的硬件,您希望使用您的数据对实际场景进行基准测试.VARCHARis stored inline with the table.VARCHARis 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 与文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL:大 VARCHAR 与文本?
基础教程推荐
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
