Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Mysql Text DataType reserves any memory space

I want to know if mysql TEXT data type reserves any space even if there is no data in that row?

I am little confuse. Can anyone provide me any input on this.

like image 883
MySQL DBA Avatar asked Aug 20 '09 12:08

MySQL DBA


People also ask

What is the limit of text in MySQL?

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.

What is the storage size of text data type?

Just like BLOB, there are four TEXT types- TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. TEXT olds up to 65,535 bytes or 64KB of data. It takes 2-byte overhead. It means that TEXT will occupy [the number of character used+2]Bytes in the memory.

What is text data type in MySQL?

The four TEXT types are TINYTEXT , TEXT , MEDIUMTEXT , and LONGTEXT . These correspond to the four BLOB types and have the same maximum lengths and storage requirements.

How does MySQL store text?

TEXT data may be stored off the table, with a pointer to the string stored on the table. Accessing data stored in this way is slower. VARCHAR data is always stored on the table. If data is frequently retrieved, inline storage offers faster performance.


1 Answers

Typically, no. text columns are actually stored away from the row, so they don't take up space on the row, per se. Instead, the row keeps a pointer to the text column (which does take up space, but only 4 bytes-ish (depends on the system) a row), but the text column itself will remain empty until you populate it.

Now, varchar columns will allocate space for their max at insertion, but only take up the space needed by its contents. char columns, however, will always use the space specified. So, here's what each column looks like with the phrase "waffles":

varchar(15): 'waffles'
char(15):    'waffles        '
text:        'waffles'

Hopefully, this helps.

like image 50
Eric Avatar answered Oct 15 '22 22:10

Eric