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.
1 Answers
InnoDB compressed row format has some prerequisites:
innodb_file_format=Barracuda
in your my.cnf file.innodb_file_per_table
in your my.cnf file. The compression doesn't work for tables stored in the central tablespace (ibdata1).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.

- 538,548
- 86
- 673
- 828
-
would this change the way I select data from the table in anyway? if my database is 1 terabyte large, would the alter table statement take a long long time? – user121196 Feb 12 '13 at 00:33
-
Karwim: will this slow down the queries? I assume it would decompress on the fly? – user121196 Feb 12 '13 at 01:36
-
I moved my comments into my answer. – Bill Karwin Feb 12 '13 at 03:49