HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

Good reason to convert LONGTEXT column to smaller width if field is smaller?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
longtextfieldcolumnconvertreasonwidthsmallergood

Problem

We have a database that uses a LONGTEXT type for a column that does not need that much space. The maximum row size currently has about 6500 characters and that's with a few million inserts so it's very unlikely we will ever need more space. Is it worthwhile to try to reduce the allocated size of this column? Will we see performance improvements?

We are using MySQL 5.6 with InnoDB.

Thanks!

Solution

Let's do the math.

  • 6500 characters, even in CHARACTER SET utf8mb4 takes no more than 26000 bytes.



  • TEXT has a limit of 64K bytes and needs a hidden 2-byte length field.



  • LONGTEXT has a 4-byte length field.



  • Let's say (for the 'math') that the average row length, including this text, is 3000 bytes.



Math...

  • Savings of switching from LONGTEXT to TEXT: 2 bytes per row



  • Percentage space savings: 2/3000 = 0.06%



  • Performance improvement: Less than that.



Conclusion... We have spent much more effort than this minuscule improvement is worth. (But you probably learned some details.)

Context

StackExchange Database Administrators Q#136498, answer score: 3

Revisions (0)

No revisions yet.