3

I have a rather large mysql database table where one field is longtext, I wish to use compress on this field, would this result in diskspace reduction? or is the storage space already allocated and it won't result in any space reduction. the storage engine is innodb.

user121196
  • 30,032
  • 57
  • 148
  • 198

1 Answers1

4

InnoDB compressed row format has some prerequisites:

  1. innodb_file_format=Barracuda in your my.cnf file.

  2. innodb_file_per_table in your my.cnf file. The compression doesn't work for tables stored in the central tablespace (ibdata1).

  3. Change a table to use compressed format.

    ALTER TABLE MyTable ROW_FORMAT=COMPRESSED
    

Then the table should be stored in the compressed format, and it will take less space.
The ratio of compression depends on your data.

note: If you had a table stored in the ibdata1 central tablespace, and you restructure the table into file-per-table, ibdata1 will not shrink! The only way to shrink ibdata1 is to dump all your InnoDB data, shutdown MySQL, rm the tablespace, restart MySQL, and reload your data.


Re your comments:

No, it shouldn't change the way you do queries.

Yes, it will take a long time. How long depends on your system. I'd recommend trying it with a smaller table first so you get a feel for it.

It needs to spend some CPU resources to compress when you write, and decompress when you read. It's common for a database server to have extra CPU resources -- databases are more typically constrained by I/O. But the speed might become a bottleneck. Again, it depends on your system, your data, and your usage. I encourage you to test carefully to see if it's a net win or not.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828