Or is MySQL optimized for certain values of n, e.g., powers of 2?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
MySQL keeps extra information about exactly how long the string in a certain VARCHAR field is. It needs either 1 or 2 bytes to store this data. Upto 255 bytes, MySQL will need only 1 extra byte to store the length of the VARCHAR. Above 255, it will use 2 bytes. So there’s one instance where a certain n will matter. But other than that, shorter is much better because MySQL will need to use much more memory when doing things involving this VARCHAR column. Doing things like sorting or operations that use in-memory temporary tables will cost a lot more if you have a VARCHAR(1000) vs VARCHAR(20).
There is a good few pages that cover this in the Schema Optimization and Indexing chapter of High Performance MySQL from Oreilly.