Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

mysql - MySQL:大型VARCHAR与TEXT?(MySQL: Large VARCHAR vs. TEXT?)

I've got a messages table in MySQL which records messages between users.

(我在MySQL中有一个消息表,该表记录了用户之间的消息。)

Apart from the typical ids and message types (all integer types) I need to save the actual message text as either VARCHAR or TEXT.

(除了典型的ID和消息类型(所有整数类型)之外,我还需要将实际消息文本另存为VARCHAR或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.

(我将前端限制设置为3000个字符,这意味着消息插入数据库的时间绝不会超过此时间。)

Is there a rationale for going with either VARCHAR(3000) or TEXT?

(是否有理由使用VARCHAR(3000)或TEXT?)

There's something about just writing VARCHAR(3000) that feels somewhat counter-intuitive.

(只是编写VARCHAR(3000)有点不合常理。)

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.

(我曾经在Stack Overflow上浏览过其他类似的文章,但是最好获得特定于这种常见消息存储类型的视图。)

  ask by Tom translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  • TEXT and BLOB is stored off the table with the table just having a pointer to the location of the actual storage.

    (TEXTBLOB存储在表外,该表仅具有指向实际存储位置的指针。)

  • VARCHAR is stored inline with the table.

    (VARCHAR与表内联存储。)

    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.

    (在大小合理的情况下, VARCHAR更快,其折衷会更快,具体取决于您的数据和硬件,您希望使用数据对真实场景进行基准测试。)

Update Whether VARCHAR or TEXT is stored inline, or off-record depends on data size, columns size, row_format, and MySQL version.

(更新 VARCHAR还是TEXT是内联存储还是非记录存储取决于数据大小,列大小,row_format和MySQL版本。)

It does not depend on "text" vs "varchar".

(它依赖于“文”与“VARCHAR”。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...