Is there any harm in choosing a large value for varchar in MySQL?

I am going to add a new column to my table with 500,000 existing rows. Is there any harm in choosing a big value for the cook? How exactly do varchars stand out for existing strings? Does it require a lot of disk space? How about memory effects at runtime?

I am looking for specific behavior specifics in MySQL that are not recommended by the general software design.

+4
source share
3 answers

There is no harm in choosing a large value for the varchar field. Only the actual data will be saved, and MySQL does not allocate the full specified length for each record. It saves the actual length of the data along with the field, so it does not need to save the registration or allocate unused memory.

+3
source

Depending on what you do. See the related documentation page for some details:

http://dev.mysql.com/doc/refman/5.0/en/char.html

The fine in disk space is no different from what you have, for example. TEXT, and in terms of performance, it MAY be actually faster.

The main problem is the maximum row size. Note that the exact meaning of this is different from the repositories. Refer to the MySQL docs for your data storage engine for maximum row size information.

I should also add that there may be performance benefits to minimize row size, but it really depends on your workload, indexing, and how large the rows are, regardless of whether it matters to you.

+1
source

MySQL VARCHAR fields store the contents, plus 2 bytes for the length. Thus, empty VARCHAR fields will use a space to mark their length.

In addition, if this is the only VARCHAR field in your table and your storage mechanism is MyISAM, this will lead to the formatting of the time series, which can lead to performance degradation (testing is confirmed).

http://dev.mysql.com/doc/refman/5.0/en/column-count-limit.html

http://dev.mysql.com/doc/refman/5.0/en/dynamic-format.html

+1
source

All Articles