I have two fields: one to store an excerpt with a max size of 500 characters, and another to store a description with a max size of 10,000 characters.
What data types should I use, TEXT or VARCHAR? And why?
After MySQL 5.0.3 VARCHAR accepts ~65000 characters. But this does not tell why I should use one type and or the other.
I’m reasoning that I should use VARCHAR for the excerpt because I can assign a size limit, and TEXT for the description field as it’s larger.
A long
VARCHARis stored in the same manner as aTEXT/BLOBfield inInnoDB(which I assume you’re using for transactionality, referential integrity and crash recovery, right?) – that is, externally to the rest of the table on disk (which may require another disk read to retrieve).source
Unless you need to index these columns (in which case
VARCHARis much faster) there is no reason to useVARCHARoverTEXTfor long fields – there are some engine specific optimisations inMySQLto 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
MyISAMan in-depth discussion on the topic is here.