Answer the question
In order to leave comments, you need to log in
SQL: What's the difference between varchar(200) and varchar(20000) in terms of resource consumption?
It has always been interesting, but so far I have not seen comments on this topic anywhere. What is the actual difference for MySQL (or maybe all SQL-like?) between, for example, a varchar(20) field and varchar(20,000)? In terms of resource consumption, efficiency and all that? Does the system somehow reserve some space for these same 20,000 characters? Or is a certain flag about the degree of "rubberness" of the field simply put?
That is, will there be a strong difference in efficiency / consumption of memory and other resources between these cases?:
1. Recording one word of 5 characters in a field with a length of 64,000 characters.
2. Write one word of 5 characters in a field of 5 characters.
Answer the question
In order to leave comments, you need to log in
"Storing the value 'hello' requires the same amount of space in both a VARCHAR(5) column and a VARCHAR(200) column. Is there an advantage to using a shorter column?
It turns out there is a big advantage. A larger column might require much more memory because MySQL often allocates fixed size chunks of memory internally.This is especially bad for sorts or operations that use temporary tables in memory.The same happens with file sorts that use temporary tables on disk.The
best strategy is to allocate such the amount of memory you really need." Source
A variable-length string. M represents the maximum column length in characters. In MySQL 5.0, the range of M is 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in MySQL 5.0.3 and later. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used. For example, utf8 characters can require up to three bytes per character, so a VARCHAR column that uses the utf8 character set can be declared to be a maximum of 21,844 characters. See Section D.7.4, “Limits on Table Column Count and Row Size”.dev.mysql.com/doc/refman/5.0/en/string-type-overvi...
MySQL stores VARCHAR values as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A VARCHAR column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question