create table employee(id int, age int, gender boolean, other varchar(1000) primary key (id)). When the small fields id, age, gender are accessed frequently, while the large field other is accessed infrequently, you can create the other column as a compressed column. Typically, only read/write operations on other trigger the compression and decompression of this column. Accessing other columns does not trigger its compression or decompression. This further reduces the storage size of row data, enabling faster access to frequently accessed small fields and achieving a further reduction in storage space for infrequently accessed large fields.BLOB (including TINYBLOB, MEDIUMBLOB, and LONGBLOB)TEXT (including TINYTEXT, MEDIUMTEXT, and LONGTEXT)VARCHARVARBINARYLONGBLOB and LONGTEXT is 232-2, which is one byte less than the 232-1 supported by the official String Type Storage Requirements.COLUMN_FORMAT in column_definition has been modified. Additionally, column compression only supports tables of the Innodb storage engine type.column_definition:data_type [NOT NULL | NULL] [DEFAULT default_value][AUTO_INCREMENT] [UNIQUE [KEY]] [[PRIMARY] KEY][COMMENT 'string'][COLLATE collation_name][COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}|COMPRESSED=[zlib]] # COMPRESSED compressed column keyword[STORAGE {DISK|MEMORY}][reference_definition]
CREATE TABLE t1(id INT PRIMARY KEY,b BLOB COMPRESSED);
CREATE TABLE t1(id INT PRIMARY KEY,b BLOB COMPRESSED=zlib);
DDL | Compression Attribute Inherited or Not |
CREATE TABLE t2 LIKE t1; | Y |
CREATE TABLE t2 SELECT * FROM t1; | Y |
CREATE TABLE t2(a BLOB) SELECT * FROM t1; | N |
DDL | Description |
ALTER TABLE t1 MODIFY COLUMN a BLOB; | Converting a compressed column to a non-compressed column |
ALTER TABLE t1 MODIFY COLUMN a BLOB COMPRESSED; | Converting a non-compressed column to a compressed column |
Parameter Name | Dynamically Provisioned | Type | Default Value | Valid Value | Description |
cdb_column_compression_enabled | Yes | bool | FALSE | TRUE/FALSE | The switch for column compression. When the switch is disabled, creating tables with compression attributes is not allowed, while existing tables with compression attributes remain unaffected. |
innodb_column_compression_zlib_wrap | Yes | bool | TRUE | TRUE/FALSE | If it is enabled, generates the zlib header and zlib footer for the data and performs an adler32 checksum. |
innodb_column_compression_zlib_strategy | Yes | Integer | 0 | [0,4] | The compression policy used for column compression. The minimum value is: 0, and the maximum value is: 4. Values 0 to 4 correspond one-to-one with the zlib compression policies Z_DEFAULT_STRATEGY, Z_FILTERED, Z_HUFFMAN_ONLY, Z_RLE, and Z_FIXED, respectively. Generally, Z_DEFAULT_STRATEGY is often optimal for text data, while Z_RLE is optimal for image data. |
innodb_column_compression_zlib_level | Yes | Integer | 6 | [0,9] | The compression level used for column compression. The minimum value is: 0, and the maximum value is: 9. A value of 0 indicates no compression. A higher value results in smaller compressed data but longer compression time. |
innodb_column_compression_threshold | Yes | Integer | 256 | [0, 0xffffffff] | The compression threshold used for column compression. The minimum value is: 1, and the maximum value is: 0xffffffff, in bytes. Only data with a length greater than or equal to this value is compressed. Otherwise, the original data remains unchanged, and only a compression header is added. |
innodb_column_compression_pct | Yes | Integer | 100 | [1, 100] | The compression ratio used for column compression. The minimum value is: 1, and the maximum value is: 100, in percentage. Data is compressed only when the compressed data size / uncompressed data size is less than this value. Otherwise, the original data remains unchanged, and only a compression header is added. |
Name | Type | Description |
Innodb_column_compressed | Integer | Number of column compressions, including compressions in both uncompressed and compressed formats. |
Innodb_column_decompressed | Integer | Number of column decompressions, including decompressions in both uncompressed and compressed formats. |
Name | Scope | Description |
Compressed column '%-.192s' can't be used in key specification | Specified compressed column name | Compression attributes cannot be specified for columns with indexes. |
Unknown compression method: %s | Compression algorithm name specified in DDL statement | Specifying an illegal compression algorithm other than zlib during create table or alter table. |
Compressed column '%-.192s' can't be used in column format specification | Specified compressed column name | In the same column, if the COLUMN_FORMAT attribute has already been specified, the compression attribute cannot be specified, where COLUMN_FORMAT is only used in NDB. |
Alter table ... discard/import tablespace not support column compression | \\ | Tables with column compression cannot execute the Alter table ... discard/import tablespace statement. |
BLOB (including TINYBLOB, MEDIUMBLOB, and LONGBLOB)TEXT (including TINYTEXT, MEDIUMTEXT, and LONGTEXT)VARCHARVARBINARYJSONCREATE TABLE t1(id INT PRIMARY KEY,b BLOB COMPRESSED);
CREATE TABLE t1(id INT PRIMARY KEY,b BLOB COLUMN_FORMAT COMPRESSED);
DDL | Compression Attribute Inherited or Not |
CREATE TABLE t2 LIKE t1; | Y |
CREATE TABLE t2 SELECT * FROM t1; | N |
CREATE TABLE t2(a BLOB) SELECT * FROM t1; | N |
DDL | Description |
ALTER TABLE t1 MODIFY COLUMN a BLOB; | Converting a compressed column to a non-compressed column. |
ALTER TABLE t1 MODIFY COLUMN a BLOB COMPRESSED; | Converting a non-compressed column to a compressed column. |
Parameter Name | Dynamically Provisioned | Type | Default Value | Valid Value | Description |
innodb_zlib_column_compression_level | Yes | UINT | 6 | [0-9] | zlib compression. 0 indicates no compression, 1 indicates the fastest compression, and 9 indicates the highest compression level. From 1 to 9, the compression speed decreases, but the compression ratio increases. |
innodb_zstd_column_compression_level | Yes | UINT | 3 | [1-22] | zstd compression. 1 indicates the fastest compression, and 22 indicates the highest compression level. From 1 to 22, the compression speed decreases, but the compression ratio increases. |
innodb_min_column_compress_length | Yes | UINT | 256 | [1,UINT_MAX32] | Controls the compression threshold, in bytes. If the original length of a column is greater than or equal to the value of this parameter, compression is performed. Otherwise, only a compression header is added, and the data is not actually compressed. |
CREATE TABLE t1(id INT PRIMARY KEY,b BLOB COMPRESSED ALGORITHM = [ZLIB|LZ4|ZSTD]);
CREATE TABLE t1(id INT PRIMARY KEY,b BLOB COLUMN_FORMAT COMPRESSED ALGORITHM = [ZLIB|LZ4|ZSTD]);
CREATE TABLE t2 (a VARCHAR(100) COMPRESSED) ENGINE=InnoDB;SHOW CREATE TABLE t2;
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan