Possible Duplicate:
MySQL: Large VARCHAR vs. TEXT?
Since VARCHAR
can have 65k bytes now, when then should TEXT
be used instead of VARCHAR
?
Some Differences Between VARCHAR and TEXT The VAR in VARCHAR means that you can set the max size to anything between 1 and 65,535. TEXT fields have a fixed max size of 65,535 characters. A VARCHAR can be part of an index whereas a TEXT field requires you to specify a prefix length, which can be part of an index.
In most circumstances, VARCHAR provides better performance, it's more flexible, and can be fully indexed. If you need to store longer strings, use MEDIUMTEXT or LONGTEXT, but be aware that very large amounts of data can be stored in columns of these types.
CHAR items, which are fixed length, are the fastest to store and retrieve but can waste storage space. VARCHAR, a variable-length string, can be slower to store and retrieve but does not waste storage space. TEXT is a character BLOB that requires more storage space and I/O than the other two.
A long VARCHAR
is stored in the same manner as a TEXT
/BLOB
field in InnoDB
.
From storage prospective BLOB, TEXT as well as long VARCHAR are handled same way by Innodb. This is why Innodb manual calls it “long columns” rather than BLOBs.
source
Unless you need to index these columns (in which case VARCHAR
is much faster) there is no reason to use VARCHAR
over TEXT
for long fields - there are some engine specific optimisations in MySQL
to tune the data retrieval according to length, and you should use the correct column type to take advantage of these.
In case you're using MyISAM
an in-depth discussion on the topic is here.
TEXT
and BLOB
are stored off the table with the table just having a pointer to the location of the actual storage.
VARCHAR
is stored inline with the table. VARCHAR
is faster when the size is reasonable.
According to this test, VARCHAR
is about thrice as fast as text.
Text should be used for really long strings of indeterminate length. Also, queries that return TEXT fields tend to be much slower than their VARCHAR counterparts.
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