MySQL Performance – Efficiency of BLOB vs VARCHAR for Variable Size Data

MySQL

When setting up a database I want to use the most efficient data type for potentially fairly long data. Currently my project is to store song titles and thoughts pertaining to that song. Some titles might be 5 characters or longer than 100 characters and the thoughts could run pretty long.

Is it more efficient to use a varchar set to 8000 or to use a blob? Is using a blob the same as a varchar, in that there is a set size it is allocated regardless of what it holds? or is it just a pointer and it doesn't really use much space on the table? Is there a certain set size of a blob in KB or is it expandable?

Best Answer

I would suggest using TEXT over BLOB.

Primary Difference

  • TEXT and BLOB is 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.

Primary Guideline

  1. Text format messages should almost always be stored as TEXT (they end up being arbitrarily long)

  2. String attributes should be stored as VARCHAR (the destination user name, the subject, etc...).


To choose on when to use VARCHAR and when to use TEXT has been discussed extensively on Stack overflow in these threads:

  1. MySQL: Large VARCHAR vs. TEXT?

  2. MySQL varchar(2000) vs text?

There is also a performance comparison thread for this on MySQL forum.