問題描述
我在 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 版本.TEXT
andBLOB
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 與文本?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!