diff --git a/include/mysql_com.h b/include/mysql_com.h index 58c28f6d074..21b3d1e4803 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -185,10 +185,10 @@ enum enum_indicator_type #define FIELD_IS_DROPPED (1U << 26) /* Intern: Field is being dropped */ #define VERS_SYS_START_FLAG (1 << 27) /* autogenerated column declared with - `generated always at row start` + `generated always as row start` (see II.a SQL Standard) */ #define VERS_SYS_END_FLAG (1 << 28) /* autogenerated column declared with - `generated always at row end` + `generated always as row end` (see II.a SQL Standard).*/ #define VERS_OPTIMIZED_UPDATE_FLAG (1 << 29) /* column that doesn't support system versioning when table diff --git a/plugin/versioning/CMakeLists.txt b/plugin/versioning/CMakeLists.txt new file mode 100644 index 00000000000..9ae0b58af66 --- /dev/null +++ b/plugin/versioning/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (c) 2016, MariaDB corporation. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +MYSQL_ADD_PLUGIN(versioning versioning.cc + MODULE_ONLY MODULE_OUTPUT_NAME "versioning" COMPONENT Test) diff --git a/plugin/versioning/versioning.cc b/plugin/versioning/versioning.cc new file mode 100644 index 00000000000..44faf85aef7 --- /dev/null +++ b/plugin/versioning/versioning.cc @@ -0,0 +1,69 @@ +/* Copyright (c) 2016, MariaDB corporation. All rights + reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include +#include +#include "sql_plugin.h" // st_plugin_int + +/* + Disable __attribute__() on non-gcc compilers. +*/ +#if !defined(__attribute__) && !defined(__GNUC__) +#define __attribute__(A) +#endif + +static int forced_versioning_init(void *p __attribute__ ((unused))) +{ + + DBUG_ENTER("forced_versioning_init"); + vers_force= true; + vers_hide= true; + DBUG_RETURN(0); +} + +static int forced_versioning_deinit(void *p __attribute__ ((unused))) +{ + DBUG_ENTER("forced_versioning_deinit"); + vers_force= false; + vers_hide= false; + DBUG_RETURN(0); +} + + +struct st_mysql_daemon forced_versioning_plugin= +{ MYSQL_DAEMON_INTERFACE_VERSION }; + +/* + Plugin library descriptor +*/ + +maria_declare_plugin(forced_versioning) +{ + MYSQL_DAEMON_PLUGIN, + &forced_versioning_plugin, + "forced_versioning", + "Natsys Lab", + "Enable System Vesioning for all newly created tables", + PLUGIN_LICENSE_GPL, + forced_versioning_init, /* Plugin Init */ + forced_versioning_deinit, /* Plugin Deinit */ + 0x0100 /* 1.0 */, + NULL, /* status variables */ + NULL, /* system variables */ + "1.0", /* string version */ + MariaDB_PLUGIN_MATURITY_EXPERIMENTAL /* maturity */ +} +maria_declare_plugin_end; diff --git a/sql/handler.cc b/sql/handler.cc index 2bbc52fb19f..909e0aa6fee 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -6669,9 +6669,17 @@ bool Vers_parse_info::fix_implicit(THD *thd, Alter_info *alter_info, bool Vers_parse_info::check_and_fix_implicit( THD *thd, Alter_info *alter_info, - bool integer_fields, + HA_CREATE_INFO *create_info, const char* table_name) { + bool integer_fields= + create_info->db_type->flags & HTON_SUPPORTS_SYS_VERSIONING; + + if (vers_force) { + declared_with_system_versioning= true; + create_info->options|= HA_VERSIONED_TABLE; + } + if (!need_to_check()) return false; diff --git a/sql/handler.h b/sql/handler.h index 19a0b2963e4..a0da6852da4 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1720,7 +1720,8 @@ private: public: bool check_and_fix_implicit(THD *thd, Alter_info *alter_info, - bool integer_fields, const char *table_name); + HA_CREATE_INFO *create_info, + const char *table_name); bool check_and_fix_alter(THD *thd, Alter_info *alter_info, HA_CREATE_INFO *create_info, TABLE_SHARE *share); bool fix_create_like(THD *thd, Alter_info *alter_info, diff --git a/sql/mysqld.cc b/sql/mysqld.cc index b7eccea80c6..bb96893e49d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -783,6 +783,8 @@ char *opt_logname, *opt_slow_logname, *opt_bin_logname; /* System Versioning */ char *temporal_current_timestamp; +my_bool vers_force= false; +my_bool vers_hide= false; /* Static variables */ diff --git a/sql/mysqld.h b/sql/mysqld.h index ece0992dd82..20300895fe5 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -176,6 +176,8 @@ extern char *opt_backup_history_logname, *opt_backup_progress_logname, extern const char *log_output_str; extern const char *log_backup_output_str; extern char *temporal_current_timestamp; +extern my_bool vers_force; +extern my_bool vers_hide; extern char *mysql_home_ptr, *pidfile_name_ptr; extern MYSQL_PLUGIN_IMPORT char glob_hostname[FN_REFLEN]; extern char mysql_home[FN_REFLEN]; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d16211101fd..677dd269722 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3876,12 +3876,9 @@ mysql_execute_command(THD *thd) if (!(create_info.used_fields & HA_CREATE_USED_ENGINE)) create_info.use_default_db_type(thd); - DBUG_ASSERT(create_info.db_type); if (!create_info.like() && create_info.vers_info.check_and_fix_implicit( - thd, &alter_info, - create_info.db_type->flags & HTON_SUPPORTS_SYS_VERSIONING, - create_table->table_name)) + thd, &alter_info, &create_info, create_table->table_name)) { goto end_with_restore_list; } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 93836c82085..0f1098dcede 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2064,6 +2064,10 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, { uint flags = field->flags; + if (vers_hide && + (flags & (VERS_SYS_START_FLAG | VERS_SYS_END_FLAG))) + continue; + if (ptr != table->field) packet->append(STRING_WITH_LEN(",\n")); @@ -2229,7 +2233,7 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, hton->index_options); } - if (table->versioned()) + if (table->versioned() && !vers_hide) { const Field *fs = table->vers_start_field(); const Field *fe = table->vers_end_field(); @@ -2278,7 +2282,7 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, add_table_options(thd, table, create_info_arg, table_list->schema_table != 0, 0, packet); - if (table->versioned()) + if (table->versioned() && !vers_hide) { packet->append(STRING_WITH_LEN(" WITH SYSTEM VERSIONING")); } diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index bc2b37d9d6d..b6f84e88d07 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -387,6 +387,14 @@ static Sys_var_charptr sys_temporal_current_timestamp( GLOBAL_VAR(temporal_current_timestamp), CMD_LINE(REQUIRED_ARG, 'b'), IN_FS_CHARSET, DEFAULT("now")); +static Sys_var_mybool Sys_vers_force( + "vers_force", "Force system versioning for all created tables", + GLOBAL_VAR(vers_force), CMD_LINE(OPT_ARG), DEFAULT(FALSE)); + +static Sys_var_mybool Sys_vers_hide( + "vers_hide", "Hide system versioning from being displayed in table info", + GLOBAL_VAR(vers_hide), CMD_LINE(OPT_ARG), DEFAULT(FALSE)); + static Sys_var_ulonglong Sys_binlog_cache_size( "binlog_cache_size", "The size of the transactional cache for " "updates to transactional engines for the binary log. "