MySQL 表中 varchar 长度的重要性

2021-11-20 00:00:00 performance sql types mysql

我有一个 MySQL 表,其中的行是动态插入的.因为我不能确定字符串的长度并且不希望它们被切断,所以我使它们 varchar(200) 通常比我需要的大得多.为 varchar 字段提供比所需更长的长度是否会对性能造成很大影响?

I have a MySQL table where rows are inserted dynamically. Because I can not be certain of the length of strings and do not want them cut off, I make them varchar(200) which is generally much bigger than I need. Is there a big performance hit in giving a varchar field much more length than necessary?

推荐答案

不,如果您存储在该列中的值始终(例如)少于 50 个字符,则将该列声明为 varchar(50)varchar(200) 具有相同的性能.

No, in the sense that if the values you're storing in that column are always (say) less than 50 characters, declaring the column as varchar(50) or varchar(200) has the same performance.

相关文章