devxlogo

Understanding UNCOMPRESSED_LENGTH in MySQL

In MySQL, once we use the COMPRESS method to compress a particular text, the LENGTH of the resultant text is not the same as that of the original text.

However, using UNCOMPRESSED_LENGTH method on the compressed text results in the exact length of the original text, even though the text is currently compressed.

Example:

SELECT UNCOMPRESSED_LENGTH(COMPRESS('MyName'))+-----------------------------------------+| UNCOMPRESSED_LENGTH(COMPRESS('MyName')) |+-----------------------------------------+|                                      6  | +-----------------------------------------+

Now, use the below query

SELECT LENGTH(COMPRESS('MyName'))+----------------------------+| LENGTH(COMPRESS('MyName')) |+----------------------------+|                         18 | +----------------------------+

This indicates the different values in length using the two different LENGTH methods.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.