OceanBase Database supports two methods for table compression. One method is to compress tables by using data encoding, and the other is to compress tables by using general algorithms such as lz4_1.0 and zstd_1.0.
When you create a table or modify table attributes in OceanBase Database, you can set the ROW_FORMAT parameter to specify whether to enable data encoding. You can also set the COMPRESSION attribute to specify the compression algorithm to be used.
Disable or enable data encoding
Disable data encoding by using the
ROW_FORMATparameter. The SQL syntax is as follows:CREATE TABLE table_name ROW_FORMAT = REDUNDANT; ALTER TABLE table_name [SET] ROW_FORMAT = REDUNDANT; CREATE TABLE table_name ROW_FORMAT = COMPACT; ALTER TABLE table_name [SET] ROW_FORMAT = COMPACT;Enable data encoding by using the
ROW_FORMATparameter. The SQL syntax is as follows:CREATE TABLE table_name ROW_FORMAT = DYNAMIC; ALTER TABLE table_name [SET] ROW_FORMAT = DYNAMIC; CREATE TABLE table_name ROW_FORMAT = COMPRESSED; ALTER TABLE table_name [SET] ROW_FORMAT = COMPRESSED; CREATE TABLE table_name ROW_FORMAT = CONDENSED; ALTER TABLE table_name [SET] ROW_FORMAT = CONDENSED; CREATE TABLE table_name ROW_FORMAT = DEFAULT; ALTER TABLE table_name [SET] ROW_FORMAT = DEFAULT;
Specify the compression algorithm
Specify the compression algorithm by using the COMPRESSION attribute. The SQL syntax is as follows:
CREATE TABLE table_name COMPRESSION 'compress_func_name';
ALTER TABLE table_name [SET] COMPRESSION 'compress_func_name';
You can set the compress_func_name parameter to none, zstd_1.0, or lz4_1.0. The value none specifies that no compression algorithm is to be used.
For more information, see Compression and encoding.
KEY_BLOCK_SIZE
MySQL databases allow you to use the KEY_BLOCK_SIZE clause in the CREATE TABLE or ALTER TABLE statement to specify the size in bytes to use for index key blocks. The clause controls the compression level of the table or index. OceanBase Database V4.2.3 and later report no error when you use the KEY_BLOCK_SIZE clause. However, as OceanBase Database is not compatible with the compression feature supported by the clause, specifying KEY_BLOCK_SIZE does not affect the behavior or performance of OceanBase Database.