If a column defined with varchar(20000)
and size of the actual data stored is around 4k-5k, Does it make any difference to MYSQL? As I read from MYSQL documentation, there is no difference in disk usage when actual data is less than declared size.
如果使用varchar(20000)定义的列和存储的实际数据大小约为4k-5k,那么它对MYSQL有什么影响吗?正如我从MYSQL文档中读到的,当实际数据小于声明的大小时,磁盘使用没有差别。
My question is, Will there be any impact in a SELECT query on this column? Could I make my queries faster by declaring the varchar
closer to the actual size I will store in it?
我的问题是,这个列的SELECT查询会有什么影响吗?我可以通过声明varchar更接近我将存储在其中的实际大小来更快地查询吗?
1 个解决方案
#1
7
No. VARCHAR
strings are stored this way: some bytes are used to store the effective lenght of the string (in your case 2 bytes I think), and then N bytes are used to store the string where N is equal to the lenght of your string.
VARCHAR字符串以这种方式存储:一些字节用于存储字符串的有效长度(在你的情况下我认为是2个字节),然后N个字节用于存储字符串,其中N等于你的长度串。
So, for example, if you store 'example'
, only 9 bytes are used.
因此,例如,如果存储'example',则仅使用9个字节。
There are no impact in SELECT
query, both for speed and memory usage.
SELECT查询对速度和内存使用都没有影响。
#1
7
No. VARCHAR
strings are stored this way: some bytes are used to store the effective lenght of the string (in your case 2 bytes I think), and then N bytes are used to store the string where N is equal to the lenght of your string.
VARCHAR字符串以这种方式存储:一些字节用于存储字符串的有效长度(在你的情况下我认为是2个字节),然后N个字节用于存储字符串,其中N等于你的长度串。
So, for example, if you store 'example'
, only 9 bytes are used.
因此,例如,如果存储'example',则仅使用9个字节。
There are no impact in SELECT
query, both for speed and memory usage.
SELECT查询对速度和内存使用都没有影响。