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.
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.