Which is best?

Put simply, use a VARCHAR field instead of TEXT for columns between 255 and 65k characters if possible as it will lead to potentially fewer disk reads and less writes.

VARCHAR
  • Max size of 65535 characters
  • Uses 2+n bytes to store the value where n is the length of the stored string.
  • Stored inline within the table like other values
  • Can be handled in memory
  • Can be indexed
TEXT
  • Max size of 65535 characters (more for mediumtext and longtext)
  • Uses 2+n bytes to store the value where n is the length of the stored string.
  • TEXT is stored off table with the table having a pointer to the location of the actual storage.
  • Using a TEXT column in a sort or in the results will require the use of a disk-based temporary table as it can’t be handled in RAM.
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *