Skip to content

Commit

Permalink
SQL: forced, hidden versioning [closes #32]
Browse files Browse the repository at this point in the history
  • Loading branch information
midenok committed May 5, 2017
1 parent cbb6742 commit 0e01038
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/mysql_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions plugin/versioning/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
69 changes: 69 additions & 0 deletions plugin/versioning/versioning.cc
Original file line number Diff line number Diff line change
@@ -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 <mysql_version.h>
#include <mysqld.h>
#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;
10 changes: 9 additions & 1 deletion sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,8 @@ struct Vers_parse_info

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,
Expand Down
2 changes: 2 additions & 0 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
2 changes: 2 additions & 0 deletions sql/mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
5 changes: 1 addition & 4 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions sql/sql_show.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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"));
}
Expand Down
8 changes: 8 additions & 0 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand Down

0 comments on commit 0e01038

Please sign in to comment.