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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述