What is the disadvantage to using a MySQL longtext sized field when every entry will fit within a mediumtext sized field?
The reason I am asking is because I have some longtext sized fields and recently realized they are much too large, but then struggled with motivating myself to make the minute change because "what's the harm?" hence the question.
MEDIUMTEXT can store up to 16,777,215 characters i.e 16,777,215 bytes or 64MB of data. It is suitable for larger text strings like books, research papers, and code backup. It takes 3-Bytes overhead.
MEDIUMTEXT: 16,777,215 - 16 MB The MEDIUMTEXT data object is useful for storing larger text strings like white papers, books, and code backup. These data objects can be as large as 16 MB (expressed as 2^24 -1) or 16,777,215 characters and require 3 bytes of overhead storage.
TEXT has a maximum length of 65,535 bytes—the same as VARCHAR. MEDIUMTEXT has a maximum length of about 16 megabytes. LONGTEXT has a maximum length of about 4 gigabytes.
A TEXT column with a maximum length of 16,777,215 (224 − 1) characters. The effective maximum length is less if the value contains multibyte characters. Each MEDIUMTEXT value is stored using a 3-byte length prefix that indicates the number of bytes in the value.
The only storage size difference is the number of bytes allocated for the "how many bytes is this field" number. From the fine manual:
TINYTEXT L + 1 bytes, where L < 2^8 TEXT L + 2 bytes, where L < 2^16 MEDIUMTEXT L + 3 bytes, where L < 2^24 LONGTEXT L + 4 bytes, where L < 2^32
So a longtext
will use one more byte than mediumtext
to store the same text. There is a bit more information in the Data Type Storage Requirements section of the manual and some more in the The BLOB and TEXT Types section.
There's no practical difference between the four TEXT types.
Mysql uses temporary tables a lot of times to execute queries. So the disadvantage of having large sized field is that MySql will reserve that much space for the column.
You will have slow execution with same data if you have that column marked at longtext compare to mediumtext
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With