Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the disadvantage to using a MySQL longtext sized field when every entry will fit within a mediumtext sized field?

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.

like image 744
darkAsPitch Avatar asked Sep 06 '11 03:09

darkAsPitch


People also ask

What is the size of Mediumtext in mysql?

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.

What is the maximum size Mediumtext can hold?

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.

What is difference between TEXT and Longtext in mysql?

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.

What is the maximum size of Charactersstored in a field declared with a TEXT?

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.


2 Answers

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.

like image 176
mu is too short Avatar answered Oct 12 '22 05:10

mu is too short


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

like image 27
shashuec Avatar answered Oct 12 '22 05:10

shashuec