views:

46

answers:

1

I'm building a highly scalable app, and I need to know which data type to use for small strings (50-1000 chars). I heard that VARCHAR is fixed sized and therefore might be faster, but with TEXT, chars might be stored in a seperate CLOB, and only a pointer in the row data. This would be smaller, but would it have any significant performance hit?

+2  A: 

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions.

If you have MySQL 5.0.3 or later, and don't need more than 65k characters, it doesn't really matter which one you use, because both TEXT and VARCHAR have a variable size in storage. If you have many texts with less than 255 characters, you can save one byte for those by choosing VARCHAR.

But on a completely different aspect, I would always choose the data type which is more appropriate for it. If you store a text, that is semantically a text that can exceed "standard" sizes easily, you should use the TEXT datatype.

poke