Possible Duplicate:
Importance of varchar length in MySQL table
When using VARCHAR (assuming this is the correct data type for a short string) does the size matter? If I set it to 20 characters, will that take up less space or be faster than 255 characters?
There is no performance impact whether you use the full length VARCHAR declaration VARCHAR(16777216) or use a smaller precision VARCHAR datatype column.
If you design VARCHAR columns much larger than the greatest size you need, you will consume more memory than you have to. This affects cache efficiency, sorting speed, etc.
In short there isn't much difference unless you go over the size of 255 in your VARCHAR which will require another byte for the length prefix. The length indicates more of a constraint on the data stored in the column than anything else.
Answer. Because the length of the column data is variable, an extra byte is added to the head of the column in order to store that length. "varchar" has a maximum size of 255 characters because the highest value the length byte can store is 0xFF, or 255.
Yes, is matter when you indexing multiple columns.
Prefixes can be up to 1000 bytes long (767 bytes for InnoDB tables). Note that prefix limits are measured in bytes, whereas the prefix length in CREATE TABLE statements is interpreted as number of characters. Be sure to take this into account when specifying a prefix length for a column that uses a multi-byte character set.
source : http://dev.mysql.com/doc/refman/5.0/en/column-indexes.html
In a latin1 collation, you can only specify up 3 columns of varchar(255)
.
While can specify up to 50 columns for varchar(20)
In-directly, without proper index, it will slow-down query speed
In terms of storage, it does not make difference,
as varchar
stand for variable-length strings
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With