Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any pitfalls of converting MySQL TEXT field to MEDIUMTEXT?

I understand the size/storage constraints of MySQL TEXT and MEDIUMTEXT fields, but I just wanted to make absolutely sure (before I sign off on a change) that I'm not looking at any adverse effects from converting a field with existing data from TEXT to MEDIUMTEXT.

My concerns are mainly performance, integrity, and disk storage.

Thanks

like image 412
scooterhanson Avatar asked Aug 18 '10 20:08

scooterhanson


People also ask

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 mysql Mediumtext?

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.

How long is 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.

What is the maximum size of character stored in a field declared with a TEXT data type?

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.


1 Answers

With regard to the performance, integrity, and disk storage in the database layer, I wouldn't worry about it.

  • Variable-length data like varchar, text, and blob is stored without padding.
  • I don't know any issues with integrity. All data types are treated atomically by the database engine.
  • Of course if you have really long text data then it will take more storage and more time for disk I/O and network bandwidth when you fetch that data. But if that's the data you need to put in the database, then that's what you have to do.

I can think of one possible impact:

Some client interface libraries pre-allocate a buffer to hold results, and they allocate enough memory for the largest possible value. The client doesn't know the length of the data before it fetches the data, so it must allocate enough space assuming the data might be as long as the data type supports.

Therefore the library would allocate 16MB per mediumtext while it would allocate 64KB for a text. This is something to watch out for if you have a low memory limit in your client layer. For instance, PHP has a memory_limit config parameter for scripts, and the buffer allocated for data result sets would count toward this.

like image 77
Bill Karwin Avatar answered Sep 22 '22 02:09

Bill Karwin