From bba224dd53105ca65e0b3ca304e95248363bfa24 Mon Sep 17 00:00:00 2001 From: Rasmus Johansson Date: Thu, 27 Oct 2016 23:24:44 +0300 Subject: [PATCH] Added server variable compression_default, which if 1/ON sets compression on for all new InnoDB/XtraDB tables by default by setting PAGE_COMPRESSED=1 --- .../r/innodb-page_compression_tables.result | 26 +++++++++++++++++++ .../t/innodb-page_compression_tables.test | 14 ++++++++++ storage/innobase/handler/ha_innodb.cc | 8 +++++- storage/xtradb/handler/ha_innodb.cc | 8 +++++- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/innodb/r/innodb-page_compression_tables.result b/mysql-test/suite/innodb/r/innodb-page_compression_tables.result index a0ac8986b9e..7d825e73aa4 100644 --- a/mysql-test/suite/innodb/r/innodb-page_compression_tables.result +++ b/mysql-test/suite/innodb/r/innodb-page_compression_tables.result @@ -123,5 +123,31 @@ drop procedure innodb_insert_proc; drop table innodb_normal; drop table innodb_compact; drop table innodb_dynamic; +CREATE TABLE no_compression (id INT NOT NULL, name VARCHAR(200)) ENGINE=InnoDB; +SET SESSION innodb_compression_default = 1; +CREATE TABLE default_compression (id INT NOT NULL, name VARCHAR(200)) ENGINE=InnoDB; +CREATE TABLE explicit_no_compression (id INT NOT NULL, name VARCHAR(200)) ENGINE=InnoDB PAGE_COMPRESSED=0; +SHOW CREATE TABLE no_compression; +Table Create Table +no_compression CREATE TABLE `no_compression` ( + `id` int(11) NOT NULL, + `name` varchar(200) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +SHOW CREATE TABLE default_compression; +Table Create Table +default_compression CREATE TABLE `default_compression` ( + `id` int(11) NOT NULL, + `name` varchar(200) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 `PAGE_COMPRESSED`='ON' +SHOW CREATE TABLE explicit_no_compression; +Table Create Table +explicit_no_compression CREATE TABLE `explicit_no_compression` ( + `id` int(11) NOT NULL, + `name` varchar(200) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 `PAGE_COMPRESSED`=0 +DROP TABLE no_compression; +DROP TABLE default_compression; +DROP TABLE explicit_no_compression; +SET SESSION innodb_compression_default = 0; Warnings: Warning 131 Using innodb_file_format is deprecated and the parameter may be removed in future releases. See http://dev.mysql.com/doc/refman/5.7/en/innodb-file-format.html diff --git a/mysql-test/suite/innodb/t/innodb-page_compression_tables.test b/mysql-test/suite/innodb/t/innodb-page_compression_tables.test index 41d844d26b4..3a241810bbc 100644 --- a/mysql-test/suite/innodb/t/innodb-page_compression_tables.test +++ b/mysql-test/suite/innodb/t/innodb-page_compression_tables.test @@ -95,6 +95,20 @@ drop table innodb_normal; drop table innodb_compact; drop table innodb_dynamic; +# MDEV-9820 introducing variable for having page compression turned on by default on InnoDB tables +# test that innodb_compression_default works as expected, i.e. if it has a value of 1 (ON) tables are by default created with page_compressed=1; +CREATE TABLE no_compression (id INT NOT NULL, name VARCHAR(200)) ENGINE=InnoDB; +SET SESSION innodb_compression_default = 1; +CREATE TABLE default_compression (id INT NOT NULL, name VARCHAR(200)) ENGINE=InnoDB; +CREATE TABLE explicit_no_compression (id INT NOT NULL, name VARCHAR(200)) ENGINE=InnoDB PAGE_COMPRESSED=0; +SHOW CREATE TABLE no_compression; +SHOW CREATE TABLE default_compression; +SHOW CREATE TABLE explicit_no_compression; +DROP TABLE no_compression; +DROP TABLE default_compression; +DROP TABLE explicit_no_compression; +SET SESSION innodb_compression_default = 0; + # reset system --disable_query_log EVAL SET GLOBAL innodb_compression_algorithm = $innodb_compression_algorithm_orig; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 30765ddd357..9f781c99920 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -684,6 +684,11 @@ srv_mbr_debug(const byte* data) static void innodb_remember_check_sysvar_funcs(); mysql_var_check_func check_sysvar_enum; +// should page compression be used by default for new tables +static MYSQL_THDVAR_BOOL(compression_default, PLUGIN_VAR_OPCMDARG, + "Is compression the default for new tables", + NULL, NULL, FALSE); + static MYSQL_THDVAR_UINT(default_encryption_key_id, PLUGIN_VAR_RQCMDARG, "Default encryption key id used for table encryption.", NULL, NULL, @@ -701,7 +706,7 @@ ha_create_table_option innodb_table_option_list[]= { /* With this option user can enable page compression feature for the table */ - HA_TOPTION_BOOL("PAGE_COMPRESSED", page_compressed, 0), + HA_TOPTION_SYSVAR("PAGE_COMPRESSED", page_compressed, compression_default), /* With this option user can set zip compression level for page compression for this table*/ HA_TOPTION_NUMBER("PAGE_COMPRESSION_LEVEL", page_compression_level, 0, 1, 9, 1), @@ -23810,6 +23815,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= { MYSQL_SYSVAR(fatal_semaphore_wait_threshold), /* Table page compression feature */ MYSQL_SYSVAR(use_trim), + MYSQL_SYSVAR(compression_default), MYSQL_SYSVAR(compression_algorithm), MYSQL_SYSVAR(mtflush_threads), MYSQL_SYSVAR(use_mtflush), diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index 900d520d242..bd02e97b739 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -620,6 +620,11 @@ ib_cb_t innodb_api_cb[] = { static void innodb_remember_check_sysvar_funcs(); mysql_var_check_func check_sysvar_enum; +// should page compression be used by default for new tables +static MYSQL_THDVAR_BOOL(compression_default, PLUGIN_VAR_OPCMDARG, + "Is compression the default for new tables", + NULL, NULL, FALSE); + static MYSQL_THDVAR_UINT(default_encryption_key_id, PLUGIN_VAR_RQCMDARG, "Default encryption key id used for table encryption.", NULL, NULL, @@ -637,7 +642,7 @@ ha_create_table_option innodb_table_option_list[]= { /* With this option user can enable page compression feature for the table */ - HA_TOPTION_BOOL("PAGE_COMPRESSED", page_compressed, 0), + HA_TOPTION_BOOL("PAGE_COMPRESSED", page_compressed, compression_default), /* With this option user can set zip compression level for page compression for this table*/ HA_TOPTION_NUMBER("PAGE_COMPRESSION_LEVEL", page_compression_level, 0, 1, 9, 1), @@ -21433,6 +21438,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= { MYSQL_SYSVAR(fatal_semaphore_wait_threshold), /* Table page compression feature */ MYSQL_SYSVAR(use_trim), + MYSQL_SYSVAR(compression_default), MYSQL_SYSVAR(compression_algorithm), MYSQL_SYSVAR(mtflush_threads), MYSQL_SYSVAR(use_mtflush),