mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 02:05:57 +01:00
parent
a86d6bad54
commit
c9520cb0c4
9 changed files with 199 additions and 226 deletions
|
@ -1,32 +1,32 @@
|
|||
create table t (a int) with system versioning;
|
||||
insert into t values (1);
|
||||
update t set a= 2;
|
||||
show global variables like 'versioning_current_timestamp';
|
||||
show global variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp NOW
|
||||
show variables like 'versioning_current_timestamp';
|
||||
versioning_asof_timestamp CURRENT
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp NOW
|
||||
versioning_asof_timestamp CURRENT
|
||||
select * from t;
|
||||
a
|
||||
2
|
||||
set versioning_current_timestamp = '2031-1-1 0:0:0';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
set versioning_asof_timestamp= '2031-1-1 0:0:0';
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp 2031-01-01 00:00:00.000000
|
||||
versioning_asof_timestamp 2031-01-01 00:00:00.000000
|
||||
select * from t;
|
||||
a
|
||||
2
|
||||
set versioning_current_timestamp = '2011-1-1 0:0:0';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
set versioning_asof_timestamp= '2011-1-1 0:0:0';
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp 2011-01-01 00:00:00.000000
|
||||
versioning_asof_timestamp 2011-01-01 00:00:00.000000
|
||||
select * from t;
|
||||
a
|
||||
set versioning_current_timestamp = 'all';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
set versioning_asof_timestamp= ALL;
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp ALL
|
||||
versioning_asof_timestamp ALL
|
||||
select * from t;
|
||||
a
|
||||
2
|
||||
|
@ -41,62 +41,68 @@ select * from (select * from t) as tt;
|
|||
a
|
||||
2
|
||||
1
|
||||
set global versioning_current_timestamp= 'alley';
|
||||
ERROR 42000: Variable 'versioning_current_timestamp' can't be set to the value of 'alley'
|
||||
set global versioning_current_timestamp= null;
|
||||
ERROR 42000: Variable 'versioning_current_timestamp' can't be set to the value of 'NULL'
|
||||
set global versioning_current_timestamp= 1;
|
||||
ERROR 42000: Incorrect argument type to variable 'versioning_current_timestamp'
|
||||
set global versioning_current_timestamp= 1.1;
|
||||
ERROR 42000: Incorrect argument type to variable 'versioning_current_timestamp'
|
||||
set versioning_current_timestamp= 'alley';
|
||||
ERROR 42000: Variable 'versioning_current_timestamp' can't be set to the value of 'alley'
|
||||
set versioning_current_timestamp= null;
|
||||
ERROR 42000: Variable 'versioning_current_timestamp' can't be set to the value of 'NULL'
|
||||
set versioning_current_timestamp= 1;
|
||||
ERROR 42000: Incorrect argument type to variable 'versioning_current_timestamp'
|
||||
set versioning_current_timestamp= 1.1;
|
||||
ERROR 42000: Incorrect argument type to variable 'versioning_current_timestamp'
|
||||
set global versioning_current_timestamp= '1911-11-11 11:11:11.1111119';
|
||||
show global variables like 'versioning_current_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp 1911-11-11 11:11:11.111111
|
||||
set global versioning_current_timestamp= '1900-01-01 00:00:00';
|
||||
show global variables like 'versioning_current_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp 1900-01-01 00:00:00.000000
|
||||
set global versioning_current_timestamp= timestamp'1911-11-11 11:11:11.1111119';
|
||||
set global versioning_asof_timestamp= 'alley';
|
||||
ERROR 42000: Variable 'versioning_asof_timestamp' can't be set to the value of 'alley'
|
||||
set global versioning_asof_timestamp= null;
|
||||
ERROR 42000: Variable 'versioning_asof_timestamp' can't be set to the value of 'NULL'
|
||||
set global versioning_asof_timestamp= 1;
|
||||
ERROR 42000: Incorrect argument type to variable 'versioning_asof_timestamp'
|
||||
set global versioning_asof_timestamp= 1.1;
|
||||
ERROR 42000: Incorrect argument type to variable 'versioning_asof_timestamp'
|
||||
set versioning_asof_timestamp= 'alley';
|
||||
ERROR 42000: Variable 'versioning_asof_timestamp' can't be set to the value of 'alley'
|
||||
set versioning_asof_timestamp= null;
|
||||
ERROR 42000: Variable 'versioning_asof_timestamp' can't be set to the value of 'NULL'
|
||||
set versioning_asof_timestamp= 1;
|
||||
ERROR 42000: Incorrect argument type to variable 'versioning_asof_timestamp'
|
||||
set versioning_asof_timestamp= 1.1;
|
||||
ERROR 42000: Incorrect argument type to variable 'versioning_asof_timestamp'
|
||||
set global versioning_asof_timestamp= '1911-11-11 11:11:11.1111119';
|
||||
Warnings:
|
||||
Note 1292 Truncated incorrect datetime value: '1911-11-11 11:11:11.1111119'
|
||||
show global variables like 'versioning_current_timestamp';
|
||||
Note 1292 Truncated incorrect datetime value: '1911-11-11 11:11:11.1111119'
|
||||
show global variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp 1911-11-11 11:11:11.111111
|
||||
set @ts= timestamp'1900-01-01 00:00:00';
|
||||
set global versioning_current_timestamp= @ts;
|
||||
show global variables like 'versioning_current_timestamp';
|
||||
versioning_asof_timestamp 1911-11-11 11:11:11.111111
|
||||
set global versioning_asof_timestamp= '1900-01-01 00:00:00';
|
||||
show global variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp 1900-01-01 00:00:00.000000
|
||||
set versioning_current_timestamp= '1911-11-11 11:11:11.1111119';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp 1911-11-11 11:11:11.111111
|
||||
set versioning_current_timestamp= '1900-01-01 00:00:00';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp 1900-01-01 00:00:00.000000
|
||||
set versioning_current_timestamp= timestamp'1911-11-11 11:11:11.1111119';
|
||||
versioning_asof_timestamp 1900-01-01 00:00:00.000000
|
||||
set global versioning_asof_timestamp= timestamp'1911-11-11 11:11:11.1111119';
|
||||
Warnings:
|
||||
Note 1292 Truncated incorrect datetime value: '1911-11-11 11:11:11.1111119'
|
||||
show variables like 'versioning_current_timestamp';
|
||||
show global variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp 1911-11-11 11:11:11.111111
|
||||
versioning_asof_timestamp 1911-11-11 11:11:11.111111
|
||||
set @ts= timestamp'1900-01-01 00:00:00';
|
||||
set versioning_current_timestamp= @ts;
|
||||
show variables like 'versioning_current_timestamp';
|
||||
set global versioning_asof_timestamp= @ts;
|
||||
show global variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_current_timestamp 1900-01-01 00:00:00.000000
|
||||
set global versioning_current_timestamp= 'now';
|
||||
set versioning_current_timestamp= 'now';
|
||||
versioning_asof_timestamp 1900-01-01 00:00:00.000000
|
||||
set versioning_asof_timestamp= '1911-11-11 11:11:11.1111119';
|
||||
Warnings:
|
||||
Note 1292 Truncated incorrect datetime value: '1911-11-11 11:11:11.1111119'
|
||||
Note 1292 Truncated incorrect datetime value: '1911-11-11 11:11:11.1111119'
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_asof_timestamp 1911-11-11 11:11:11.111111
|
||||
set versioning_asof_timestamp= '1900-01-01 00:00:00';
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_asof_timestamp 1900-01-01 00:00:00.000000
|
||||
set versioning_asof_timestamp= timestamp'1911-11-11 11:11:11.1111119';
|
||||
Warnings:
|
||||
Note 1292 Truncated incorrect datetime value: '1911-11-11 11:11:11.1111119'
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_asof_timestamp 1911-11-11 11:11:11.111111
|
||||
set @ts= timestamp'1900-01-01 00:00:00';
|
||||
set versioning_asof_timestamp= @ts;
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
Variable_name Value
|
||||
versioning_asof_timestamp 1900-01-01 00:00:00.000000
|
||||
set global versioning_asof_timestamp= CURRENT;
|
||||
set versioning_asof_timestamp= CURRENT;
|
||||
show variables where variable_name = "versioning_hide";
|
||||
Variable_name Value
|
||||
versioning_hide IMPLICIT
|
||||
|
|
|
@ -2,20 +2,20 @@ create table t (a int) with system versioning;
|
|||
insert into t values (1);
|
||||
update t set a= 2;
|
||||
|
||||
show global variables like 'versioning_current_timestamp';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
show global variables like 'versioning_asof_timestamp';
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
select * from t;
|
||||
|
||||
set versioning_current_timestamp = '2031-1-1 0:0:0';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
set versioning_asof_timestamp= '2031-1-1 0:0:0';
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
select * from t;
|
||||
|
||||
set versioning_current_timestamp = '2011-1-1 0:0:0';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
set versioning_asof_timestamp= '2011-1-1 0:0:0';
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
select * from t;
|
||||
|
||||
set versioning_current_timestamp = 'all';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
set versioning_asof_timestamp= ALL;
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
select * from t;
|
||||
|
||||
create view vt as select * from t;
|
||||
|
@ -26,54 +26,54 @@ select * from (select * from t) as tt;
|
|||
|
||||
# global
|
||||
--error ER_WRONG_VALUE_FOR_VAR
|
||||
set global versioning_current_timestamp= 'alley';
|
||||
set global versioning_asof_timestamp= 'alley';
|
||||
--error ER_WRONG_VALUE_FOR_VAR
|
||||
set global versioning_current_timestamp= null;
|
||||
set global versioning_asof_timestamp= null;
|
||||
--error ER_WRONG_TYPE_FOR_VAR
|
||||
set global versioning_current_timestamp= 1;
|
||||
set global versioning_asof_timestamp= 1;
|
||||
--error ER_WRONG_TYPE_FOR_VAR
|
||||
set global versioning_current_timestamp= 1.1;
|
||||
set global versioning_asof_timestamp= 1.1;
|
||||
|
||||
# session
|
||||
--error ER_WRONG_VALUE_FOR_VAR
|
||||
set versioning_current_timestamp= 'alley';
|
||||
set versioning_asof_timestamp= 'alley';
|
||||
--error ER_WRONG_VALUE_FOR_VAR
|
||||
set versioning_current_timestamp= null;
|
||||
set versioning_asof_timestamp= null;
|
||||
--error ER_WRONG_TYPE_FOR_VAR
|
||||
set versioning_current_timestamp= 1;
|
||||
set versioning_asof_timestamp= 1;
|
||||
--error ER_WRONG_TYPE_FOR_VAR
|
||||
set versioning_current_timestamp= 1.1;
|
||||
set versioning_asof_timestamp= 1.1;
|
||||
|
||||
# global
|
||||
set global versioning_current_timestamp= '1911-11-11 11:11:11.1111119';
|
||||
show global variables like 'versioning_current_timestamp';
|
||||
set global versioning_asof_timestamp= '1911-11-11 11:11:11.1111119';
|
||||
show global variables like 'versioning_asof_timestamp';
|
||||
|
||||
set global versioning_current_timestamp= '1900-01-01 00:00:00';
|
||||
show global variables like 'versioning_current_timestamp';
|
||||
set global versioning_asof_timestamp= '1900-01-01 00:00:00';
|
||||
show global variables like 'versioning_asof_timestamp';
|
||||
|
||||
set global versioning_current_timestamp= timestamp'1911-11-11 11:11:11.1111119';
|
||||
show global variables like 'versioning_current_timestamp';
|
||||
set global versioning_asof_timestamp= timestamp'1911-11-11 11:11:11.1111119';
|
||||
show global variables like 'versioning_asof_timestamp';
|
||||
|
||||
set @ts= timestamp'1900-01-01 00:00:00';
|
||||
set global versioning_current_timestamp= @ts;
|
||||
show global variables like 'versioning_current_timestamp';
|
||||
set global versioning_asof_timestamp= @ts;
|
||||
show global variables like 'versioning_asof_timestamp';
|
||||
|
||||
# session
|
||||
set versioning_current_timestamp= '1911-11-11 11:11:11.1111119';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
set versioning_asof_timestamp= '1911-11-11 11:11:11.1111119';
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
|
||||
set versioning_current_timestamp= '1900-01-01 00:00:00';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
set versioning_asof_timestamp= '1900-01-01 00:00:00';
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
|
||||
set versioning_current_timestamp= timestamp'1911-11-11 11:11:11.1111119';
|
||||
show variables like 'versioning_current_timestamp';
|
||||
set versioning_asof_timestamp= timestamp'1911-11-11 11:11:11.1111119';
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
|
||||
set @ts= timestamp'1900-01-01 00:00:00';
|
||||
set versioning_current_timestamp= @ts;
|
||||
show variables like 'versioning_current_timestamp';
|
||||
set versioning_asof_timestamp= @ts;
|
||||
show variables like 'versioning_asof_timestamp';
|
||||
|
||||
set global versioning_current_timestamp= 'now';
|
||||
set versioning_current_timestamp= 'now';
|
||||
set global versioning_asof_timestamp= CURRENT;
|
||||
set versioning_asof_timestamp= CURRENT;
|
||||
|
||||
show variables where variable_name = "versioning_hide";
|
||||
select * from t for system_time all;
|
||||
|
|
|
@ -9450,15 +9450,27 @@ mysqld_get_one_option(int optid, const struct my_option *opt, char *argument)
|
|||
WSREP_SYNC_WAIT_BEFORE_READ);
|
||||
break;
|
||||
#endif /* WITH_WSREP */
|
||||
case OPT_VERS_CURRENT_TIME:
|
||||
sys_var *var= static_cast<sys_var*>(opt->app_type);
|
||||
DBUG_ASSERT(var);
|
||||
if (var->option_updated())
|
||||
case OPT_VERS_ASOF_TIMESTAMP:
|
||||
int type= find_type(argument, opt->typelib, FIND_TYPE_BASIC);
|
||||
st_vers_asof_timestamp &out= global_system_variables.vers_asof_timestamp;
|
||||
if (type)
|
||||
{
|
||||
sql_print_error("Can't start server: "
|
||||
"cannot process --vers-current-time=%.*s",
|
||||
FN_REFLEN, argument);
|
||||
return 1;
|
||||
out.type= type - 1;
|
||||
DBUG_ASSERT(out.type < FOR_SYSTEM_TIME_AS_OF);
|
||||
}
|
||||
else
|
||||
{
|
||||
out.type= FOR_SYSTEM_TIME_AS_OF;
|
||||
MYSQL_TIME_STATUS status;
|
||||
bool err= str_to_datetime(argument, strlen(argument), &out.ltime, 0, &status);
|
||||
if (err || (status.warnings & ~MYSQL_TIME_NOTE_TRUNCATED))
|
||||
{
|
||||
sql_print_error("Can't start server: "
|
||||
"cannot process --%s=%.*s",
|
||||
opt->name,
|
||||
FN_REFLEN, argument);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
21
sql/mysqld.h
21
sql/mysqld.h
|
@ -184,25 +184,24 @@ extern const char *log_backup_output_str;
|
|||
enum vers_range_type_t
|
||||
{
|
||||
FOR_SYSTEM_TIME_UNSPECIFIED = 0,
|
||||
FOR_SYSTEM_TIME_ALL,
|
||||
FOR_SYSTEM_TIME_AS_OF,
|
||||
FOR_SYSTEM_TIME_FROM_TO,
|
||||
FOR_SYSTEM_TIME_BETWEEN,
|
||||
FOR_SYSTEM_TIME_ALL,
|
||||
FOR_SYSTEM_TIME_BEFORE
|
||||
};
|
||||
|
||||
/* Used only for @@versioning_current_time sysvar. This struct must be POD
|
||||
* because of str_value, which is used as interface to user.
|
||||
* So no virtual-anything! */
|
||||
struct st_vers_current_time
|
||||
struct st_vers_asof_timestamp
|
||||
{
|
||||
char *str_value; // must be first
|
||||
vers_range_type_t type;
|
||||
const char *getopt_value;
|
||||
ulong type;
|
||||
MYSQL_TIME ltime;
|
||||
st_vers_current_time() :
|
||||
str_value(NULL),
|
||||
st_vers_asof_timestamp() :
|
||||
getopt_value(NULL),
|
||||
type(FOR_SYSTEM_TIME_UNSPECIFIED)
|
||||
{}
|
||||
{
|
||||
DBUG_ASSERT((void *)this == &this->getopt_value);
|
||||
}
|
||||
};
|
||||
|
||||
enum vers_hide_enum
|
||||
|
@ -702,7 +701,7 @@ enum options_mysqld
|
|||
OPT_SSL_KEY,
|
||||
OPT_THREAD_CONCURRENCY,
|
||||
OPT_WANT_CORE,
|
||||
OPT_VERS_CURRENT_TIME,
|
||||
OPT_VERS_ASOF_TIMESTAMP,
|
||||
#ifdef WITH_WSREP
|
||||
OPT_WSREP_CAUSAL_READS,
|
||||
OPT_WSREP_SYNC_WAIT,
|
||||
|
|
|
@ -224,13 +224,6 @@ private:
|
|||
virtual bool session_update(THD *thd, set_var *var) = 0;
|
||||
virtual bool global_update(THD *thd, set_var *var) = 0;
|
||||
|
||||
public:
|
||||
virtual bool option_updated()
|
||||
{
|
||||
DBUG_ASSERT(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
A pointer to a value of the variable for SHOW.
|
||||
|
|
|
@ -703,7 +703,7 @@ typedef struct system_variables
|
|||
uint column_compression_zlib_level;
|
||||
ulong in_subquery_conversion_threshold;
|
||||
|
||||
st_vers_current_time vers_current_time;
|
||||
st_vers_asof_timestamp vers_asof_timestamp;
|
||||
my_bool vers_force;
|
||||
ulong vers_hide;
|
||||
my_bool vers_innodb_algorithm_simple;
|
||||
|
|
|
@ -673,8 +673,8 @@ setup_without_group(THD *thd, Ref_ptr_array ref_pointer_array,
|
|||
|
||||
bool vers_select_conds_t::init_from_sysvar(THD *thd)
|
||||
{
|
||||
st_vers_current_time &in= thd->variables.vers_current_time;
|
||||
type= in.type;
|
||||
st_vers_asof_timestamp &in= thd->variables.vers_asof_timestamp;
|
||||
type= (vers_range_type_t) in.type;
|
||||
unit_start= UNIT_TIMESTAMP;
|
||||
if (type != FOR_SYSTEM_TIME_UNSPECIFIED && type != FOR_SYSTEM_TIME_ALL)
|
||||
{
|
||||
|
|
|
@ -387,23 +387,25 @@ static Sys_var_charptr Sys_my_bind_addr(
|
|||
READ_ONLY GLOBAL_VAR(my_bind_addr_str), CMD_LINE(REQUIRED_ARG),
|
||||
IN_FS_CHARSET, DEFAULT(0));
|
||||
|
||||
static Sys_var_vers_asof Sys_vers_current_time(
|
||||
"versioning_current_timestamp", "Default AS OF value for versioned tables",
|
||||
SESSION_VAR(vers_current_time), CMD_LINE(REQUIRED_ARG, OPT_VERS_CURRENT_TIME),
|
||||
IN_FS_CHARSET, DEFAULT("now"));
|
||||
const char *Sys_var_vers_asof::asof_keywords[]= {"CURRENT", "ALL", NULL};
|
||||
static Sys_var_vers_asof Sys_vers_asof_timestamp(
|
||||
"versioning_asof_timestamp", "Default AS OF value for versioned queries",
|
||||
SESSION_VAR(vers_asof_timestamp.getopt_value), CMD_LINE(REQUIRED_ARG, OPT_VERS_ASOF_TIMESTAMP),
|
||||
Sys_var_vers_asof::asof_keywords, DEFAULT(FOR_SYSTEM_TIME_UNSPECIFIED));
|
||||
|
||||
static Sys_var_mybool Sys_vers_force(
|
||||
"versioning_force", "Force system versioning for all created tables",
|
||||
SESSION_VAR(vers_force), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
|
||||
|
||||
static const char *vers_hide_keywords[]= {"AUTO", "IMPLICIT", "FULL", "NEVER", NullS};
|
||||
static const char *vers_hide_keywords[]= {"AUTO", "IMPLICIT", "FULL", "NEVER", NULL};
|
||||
static Sys_var_enum Sys_vers_hide(
|
||||
"versioning_hide", "Hide system versioning from being displayed in table info. "
|
||||
"AUTO: hide implicit system fields only in non-versioned and AS OF queries; "
|
||||
"IMPLICIT: hide implicit system fields in all queries; "
|
||||
"FULL: hide any system fields in all queries and hide versioning info in SHOW commands; "
|
||||
"NEVER: don't hide system fields",
|
||||
SESSION_VAR(vers_hide), CMD_LINE(OPT_ARG), vers_hide_keywords, DEFAULT(VERS_HIDE_AUTO));
|
||||
SESSION_VAR(vers_hide), CMD_LINE(REQUIRED_ARG),
|
||||
vers_hide_keywords, DEFAULT(VERS_HIDE_AUTO));
|
||||
|
||||
static Sys_var_mybool Sys_vers_innodb_algorithm_simple(
|
||||
"versioning_innodb_algorithm_simple",
|
||||
|
@ -411,14 +413,13 @@ static Sys_var_mybool Sys_vers_innodb_algorithm_simple(
|
|||
SESSION_VAR(vers_innodb_algorithm_simple), CMD_LINE(OPT_ARG),
|
||||
DEFAULT(TRUE));
|
||||
|
||||
static const char *vers_alter_history_keywords[]= {"KEEP", "SURVIVE", "DROP",
|
||||
NULL};
|
||||
static const char *vers_alter_history_keywords[]= {"KEEP", "SURVIVE", "DROP", NULL};
|
||||
static Sys_var_enum Sys_vers_alter_history(
|
||||
"versioning_alter_history", "Versioning ALTER TABLE mode. "
|
||||
"KEEP: leave historical system rows as is on ALTER TABLE; "
|
||||
"SURVIVE: use DDL survival feature; "
|
||||
"DROP: delete historical system rows on ALTER TABLE",
|
||||
SESSION_VAR(vers_alter_history), CMD_LINE(OPT_ARG),
|
||||
SESSION_VAR(vers_alter_history), CMD_LINE(REQUIRED_ARG),
|
||||
vers_alter_history_keywords, DEFAULT(VERS_ALTER_HISTORY_KEEP));
|
||||
|
||||
static Sys_var_ulonglong Sys_binlog_cache_size(
|
||||
|
|
150
sql/sys_vars.ic
150
sql/sys_vars.ic
|
@ -2604,129 +2604,91 @@ public:
|
|||
};
|
||||
|
||||
|
||||
class Sys_var_vers_asof: public sys_var
|
||||
class Sys_var_vers_asof: public Sys_var_enum
|
||||
{
|
||||
public:
|
||||
Sys_var_vers_asof(const char *name_arg, const char *comment, int flag_args,
|
||||
ptrdiff_t off, size_t size, CMD_LINE getopt, enum charset_enum is_os_charset_arg,
|
||||
const char *def_val, on_check_function on_check_func=0, on_update_function on_update_func=0) :
|
||||
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id, getopt.arg_type,
|
||||
SHOW_CHAR, (intptr) def_val, 0, VARIABLE_NOT_IN_BINLOG, on_check_func, on_update_func, 0)
|
||||
static const char *asof_keywords[];
|
||||
|
||||
public:
|
||||
Sys_var_vers_asof(const char *name_arg,
|
||||
const char *comment, int flag_args, ptrdiff_t off, size_t size,
|
||||
CMD_LINE getopt, const char *values[],
|
||||
uint def_val)
|
||||
: Sys_var_enum(name_arg, comment, flag_args, off, size,
|
||||
getopt, values, def_val)
|
||||
{
|
||||
option.var_type|= GET_STR;
|
||||
if (global_update(def_val))
|
||||
// setval() accepts string rather enum
|
||||
option.var_type= GET_STR;
|
||||
}
|
||||
virtual bool do_check(THD *thd, set_var *var)
|
||||
{
|
||||
if (!Sys_var_enum::do_check(thd, var))
|
||||
return false;
|
||||
MYSQL_TIME ltime;
|
||||
bool res= var->value->get_date(<ime, 0);
|
||||
if (!res)
|
||||
{
|
||||
DBUG_ASSERT(false);
|
||||
var->save_result.ulonglong_value= FOR_SYSTEM_TIME_AS_OF;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool do_check(THD *thd, set_var *var)
|
||||
{ return false; }
|
||||
private:
|
||||
bool update(set_var *var, st_vers_asof_timestamp &out)
|
||||
{
|
||||
bool res= false;
|
||||
out.type= var->save_result.ulonglong_value;
|
||||
if (out.type == FOR_SYSTEM_TIME_AS_OF)
|
||||
{
|
||||
res= var->value->get_date(&out.ltime, 0);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool update(String &in, st_vers_current_time &out)
|
||||
public:
|
||||
virtual bool global_update(THD *thd, set_var *var)
|
||||
{
|
||||
if (in.length() == 3 && 0 == my_strcasecmp(in.charset(), "ALL", in.ptr()))
|
||||
{
|
||||
out.type= FOR_SYSTEM_TIME_ALL;
|
||||
}
|
||||
else if (in.length() == 3 && 0 == my_strcasecmp(in.charset(), "NOW", in.ptr()))
|
||||
{
|
||||
out.type= FOR_SYSTEM_TIME_UNSPECIFIED;
|
||||
}
|
||||
else
|
||||
{
|
||||
MYSQL_TIME_STATUS status;
|
||||
if (str_to_datetime(in.ptr(), in.length(), &out.ltime, flags, &status) ||
|
||||
out.ltime.time_type != MYSQL_TIMESTAMP_DATETIME ||
|
||||
(status.warnings & ~MYSQL_TIME_NOTE_TRUNCATED) != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
out.type= FOR_SYSTEM_TIME_AS_OF;
|
||||
}
|
||||
return false;
|
||||
return update(var, global_var(st_vers_asof_timestamp));
|
||||
}
|
||||
bool update(THD *thd, set_var *var, st_vers_current_time &out)
|
||||
virtual bool session_update(THD *thd, set_var *var)
|
||||
{
|
||||
Item *item= var->value;
|
||||
return update(var, session_var(thd, st_vers_asof_timestamp));
|
||||
}
|
||||
|
||||
switch (item->result_type())
|
||||
{
|
||||
case TIME_RESULT:
|
||||
{
|
||||
if (item->get_date(&out.ltime, 0))
|
||||
break;
|
||||
out.type= FOR_SYSTEM_TIME_AS_OF;
|
||||
return false;
|
||||
}
|
||||
|
||||
case STRING_RESULT:
|
||||
{
|
||||
String *str= item->val_str();
|
||||
if (!str || update(*str, out))
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
String *str= item->val_str();
|
||||
const char *cstr= str ? str->c_ptr_safe() : "NULL";
|
||||
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name.str, cstr);
|
||||
return true;
|
||||
}
|
||||
bool global_update(const char *in)
|
||||
{
|
||||
String s(in, &my_charset_utf8_general_ci);
|
||||
return update(s, global_var(st_vers_current_time));
|
||||
}
|
||||
bool option_updated()
|
||||
{
|
||||
return global_update(global_var(st_vers_current_time).str_value);
|
||||
}
|
||||
bool global_update(THD *thd, set_var *var)
|
||||
{
|
||||
return update(thd, var, global_var(st_vers_current_time));
|
||||
}
|
||||
bool session_update(THD *thd, set_var *var)
|
||||
{
|
||||
return update(thd, var, session_var(thd, st_vers_current_time));
|
||||
}
|
||||
uchar *valptr(THD *thd, st_vers_current_time &val)
|
||||
private:
|
||||
uchar *value_ptr(THD *thd, st_vers_asof_timestamp &val)
|
||||
{
|
||||
switch (val.type)
|
||||
{
|
||||
case FOR_SYSTEM_TIME_UNSPECIFIED:
|
||||
return (uchar*) thd->strdup("NOW");
|
||||
case FOR_SYSTEM_TIME_ALL:
|
||||
return (uchar*) thd->strdup("ALL");
|
||||
return (uchar*) thd->strdup(asof_keywords[val.type]);
|
||||
case FOR_SYSTEM_TIME_AS_OF:
|
||||
{
|
||||
uchar *buf= (uchar*) thd->alloc(MAX_DATE_STRING_REP_LENGTH);
|
||||
if (buf &&!my_datetime_to_str(&val.ltime, (char*) buf, 6))
|
||||
{
|
||||
uchar *buf= (uchar*) thd->alloc(MAX_DATE_STRING_REP_LENGTH);
|
||||
if (buf)
|
||||
{
|
||||
if (!my_datetime_to_str(&val.ltime, (char*) buf, 6))
|
||||
{
|
||||
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "vers_current_time", "NULL (wrong datetime)");
|
||||
return (uchar*) thd->strdup("Error: wrong datetime");
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "versioning_asof_timestamp", "NULL (wrong datetime)");
|
||||
return (uchar*) thd->strdup("Error: wrong datetime");
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "vers_current_time", "NULL (wrong range type)");
|
||||
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "versioning_asof_timestamp", "NULL (wrong range type)");
|
||||
return (uchar*) thd->strdup("Error: wrong range type");
|
||||
}
|
||||
void session_save_default(THD *thd, set_var *var)
|
||||
{ DBUG_ASSERT(false); }
|
||||
void global_save_default(THD *thd, set_var *var)
|
||||
{ DBUG_ASSERT(false); }
|
||||
uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
|
||||
{ return valptr(thd, session_var(thd, st_vers_current_time)); }
|
||||
uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
|
||||
{ return valptr(thd, global_var(st_vers_current_time)); }
|
||||
uchar *default_value_ptr(THD *thd)
|
||||
{ return (uchar *)option.def_value; }
|
||||
|
||||
public:
|
||||
virtual uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base)
|
||||
{ return value_ptr(thd, session_var(thd, st_vers_asof_timestamp)); }
|
||||
virtual uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base)
|
||||
{ return value_ptr(thd, global_var(st_vers_asof_timestamp)); }
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue