Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL TEXT memory allocation

Tags:

memory

mysql

Anybody knows how MySQL allocates disk space for fields like "TEXT" or "BLOB"

For example, what happens when I insert 10kb string into "TEXT" column? Is the entire 65kb data allocated or only 10kb?

like image 533
Rafał Figura Avatar asked Aug 16 '16 07:08

Rafał Figura


People also ask

Where does the OS and MySQL allocate the Ram?

⚈ OS allocations are pinned to the 'first' CPU's RAM.] ⚈ Other allocations go by default to the first CPU until it is full. Now for the problem. ⚈ The OS and MySQL have allocated all the 'first' RAM. ⚈ MySQL has allocated some of the second RAM.

What are the best practices for configuring MySQL memory usage?

The first rule of configuring MySQL memory usage is you never want your MySQL to cause the operating system to swap. Even minor swapping activity can dramatically reduce MySQL performance. Note the keyword “activity” here. It is fine to have some used space in your swap file,...

What are text data objects in MySQL?

TEXT data objects, as their namesake implies, are useful for storing long-form text strings in a MySQL database. The four TEXT data object types are built for storing and displaying substantial amounts of information as opposed to other data object types that are helpful with tasks like...

What happens if you configure MySQL memory usage wrong?

But configuring it incorrectly can result in even worse performance (or even crashes). The first rule of configuring MySQL memory usage is you never want your MySQL to cause the operating system to swap. Even minor swapping activity can dramatically reduce MySQL performance.


1 Answers

This is explained in the documentation: http://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html

BLOB, TEXT              L + 2 bytes, where L < 2^16
MEDIUMBLOB, MEDIUMTEXT  L + 3 bytes, where L < 2^24 
LONGBLOB, LONGTEXT      L + 4 bytes, where L < 2^32

Variable-length string types are stored using a length prefix plus data. The length prefix requires from one to four bytes depending on the data type, and the value of the prefix is L (the byte length of the string). For example, storage for a MEDIUMTEXT value requires L bytes to store the value plus three bytes to store the length of the value.

So in short, the whole 65kb is not wasted.

like image 193
e4c5 Avatar answered Oct 12 '22 22:10

e4c5