Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Performance impact if stored varchar data is less than the defined size limit?

Tags:

mysql

varchar

If a column defined with varchar(20000) and size of the actual data stored is around 4k-5k, Does it make any difference to MYSQL? As I read from MYSQL documentation, there is no difference in disk usage when actual data is less than declared size.

My question is, Will there be any impact in a SELECT query on this column? Could I make my queries faster by declaring the varchar closer to the actual size I will store in it?

like image 761
user1083206 Avatar asked Dec 06 '11 09:12

user1083206


1 Answers

No. VARCHAR strings are stored this way: some bytes are used to store the effective lenght of the string (in your case 2 bytes I think), and then N bytes are used to store the string where N is equal to the lenght of your string.

So, for example, if you store 'example', only 9 bytes are used.

There are no impact in SELECT query, both for speed and memory usage.

like image 98
lorenzo-s Avatar answered Oct 13 '22 00:10

lorenzo-s