mirror of
https://github.com/MariaDB/server.git
synced 2025-08-05 13:16:09 +03:00
SQL, Tests: temporal_current_timestamp for setting default AS OF timestamp [closes #117]
This commit is contained in:
38
mysql-test/suite/versioning/r/variables.result
Normal file
38
mysql-test/suite/versioning/r/variables.result
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
create table t (a int) with system versioning;
|
||||||
|
insert into t values (1);
|
||||||
|
update t set a=2;
|
||||||
|
select * from t;
|
||||||
|
a
|
||||||
|
2
|
||||||
|
show variables where Variable_name like "temporal_current_timestamp%";
|
||||||
|
Variable_name Value
|
||||||
|
temporal_current_timestamp now
|
||||||
|
set global temporal_current_timestamp = '2031-1-1 0:0:0';
|
||||||
|
select * from t;
|
||||||
|
a
|
||||||
|
2
|
||||||
|
set global temporal_current_timestamp = '2011-1-1 0:0:0';
|
||||||
|
select * from t;
|
||||||
|
a
|
||||||
|
set global temporal_current_timestamp = 'all';
|
||||||
|
select * from t;
|
||||||
|
a
|
||||||
|
2
|
||||||
|
1
|
||||||
|
show variables where Variable_name like "temporal_current_timestamp%";
|
||||||
|
Variable_name Value
|
||||||
|
temporal_current_timestamp all
|
||||||
|
create view vt as select * from t;
|
||||||
|
select * from t;
|
||||||
|
a
|
||||||
|
2
|
||||||
|
1
|
||||||
|
drop view vt;
|
||||||
|
select * from (select * from t) as tt;
|
||||||
|
a
|
||||||
|
2
|
||||||
|
1
|
||||||
|
set session temporal_current_timestamp = 'now';
|
||||||
|
ERROR HY000: Variable 'temporal_current_timestamp' is a GLOBAL variable and should be set with SET GLOBAL
|
||||||
|
drop table t;
|
||||||
|
set global temporal_current_timestamp = 'now';
|
28
mysql-test/suite/versioning/t/variables.test
Normal file
28
mysql-test/suite/versioning/t/variables.test
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
create table t (a int) with system versioning;
|
||||||
|
insert into t values (1);
|
||||||
|
update t set a=2;
|
||||||
|
|
||||||
|
select * from t;
|
||||||
|
show variables where Variable_name like "temporal_current_timestamp%";
|
||||||
|
|
||||||
|
set global temporal_current_timestamp = '2031-1-1 0:0:0';
|
||||||
|
select * from t;
|
||||||
|
|
||||||
|
set global temporal_current_timestamp = '2011-1-1 0:0:0';
|
||||||
|
select * from t;
|
||||||
|
|
||||||
|
set global temporal_current_timestamp = 'all';
|
||||||
|
select * from t;
|
||||||
|
show variables where Variable_name like "temporal_current_timestamp%";
|
||||||
|
|
||||||
|
create view vt as select * from t;
|
||||||
|
select * from t;
|
||||||
|
drop view vt;
|
||||||
|
|
||||||
|
select * from (select * from t) as tt;
|
||||||
|
|
||||||
|
--error ER_GLOBAL_VARIABLE
|
||||||
|
set session temporal_current_timestamp = 'now';
|
||||||
|
|
||||||
|
drop table t;
|
||||||
|
set global temporal_current_timestamp = 'now';
|
@@ -781,6 +781,9 @@ char *relay_log_info_file, *report_user, *report_password, *report_host;
|
|||||||
char *opt_relay_logname = 0, *opt_relaylog_index_name=0;
|
char *opt_relay_logname = 0, *opt_relaylog_index_name=0;
|
||||||
char *opt_logname, *opt_slow_logname, *opt_bin_logname;
|
char *opt_logname, *opt_slow_logname, *opt_bin_logname;
|
||||||
|
|
||||||
|
/* System Versioning */
|
||||||
|
char *temporal_current_timestamp;
|
||||||
|
|
||||||
/* Static variables */
|
/* Static variables */
|
||||||
|
|
||||||
static volatile sig_atomic_t kill_in_progress;
|
static volatile sig_atomic_t kill_in_progress;
|
||||||
|
@@ -175,6 +175,7 @@ extern char *opt_backup_history_logname, *opt_backup_progress_logname,
|
|||||||
*opt_backup_settings_name;
|
*opt_backup_settings_name;
|
||||||
extern const char *log_output_str;
|
extern const char *log_output_str;
|
||||||
extern const char *log_backup_output_str;
|
extern const char *log_backup_output_str;
|
||||||
|
extern char *temporal_current_timestamp;
|
||||||
extern char *mysql_home_ptr, *pidfile_name_ptr;
|
extern char *mysql_home_ptr, *pidfile_name_ptr;
|
||||||
extern MYSQL_PLUGIN_IMPORT char glob_hostname[FN_REFLEN];
|
extern MYSQL_PLUGIN_IMPORT char glob_hostname[FN_REFLEN];
|
||||||
extern char mysql_home[FN_REFLEN];
|
extern char mysql_home[FN_REFLEN];
|
||||||
|
@@ -62,6 +62,7 @@
|
|||||||
#include <my_bit.h>
|
#include <my_bit.h>
|
||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
#include <ft_global.h>
|
#include <ft_global.h>
|
||||||
|
#include "sys_vars_shared.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
A key part number that means we're using a fulltext scan.
|
A key part number that means we're using a fulltext scan.
|
||||||
@@ -775,6 +776,28 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
|||||||
DBUG_RETURN(-1);
|
DBUG_RETURN(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (vers_conditions.type == FOR_SYSTEM_TIME_UNSPECIFIED)
|
||||||
|
{
|
||||||
|
const char var[]= "temporal_current_timestamp";
|
||||||
|
sys_var *sv= intern_find_sys_var(var, sizeof(var) - 1);
|
||||||
|
DBUG_ASSERT(sv);
|
||||||
|
const char *data= *(char **)sv->option.value;
|
||||||
|
DBUG_ASSERT(data);
|
||||||
|
if (0 == strcmp(data, "all"))
|
||||||
|
{
|
||||||
|
vers_conditions.init(FOR_SYSTEM_TIME_ALL, UNIT_TIMESTAMP);
|
||||||
|
}
|
||||||
|
else if (0 != strcmp(data, "now"))
|
||||||
|
{
|
||||||
|
Item *ts= create_temporal_literal(thd, data, strlen(data),
|
||||||
|
system_charset_info,
|
||||||
|
MYSQL_TYPE_DATETIME, true);
|
||||||
|
if (!ts)
|
||||||
|
DBUG_RETURN(-1);
|
||||||
|
vers_conditions.init(FOR_SYSTEM_TIME_AS_OF, UNIT_TIMESTAMP, ts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (vers_conditions.type != FOR_SYSTEM_TIME_UNSPECIFIED)
|
if (vers_conditions.type != FOR_SYSTEM_TIME_UNSPECIFIED)
|
||||||
{
|
{
|
||||||
switch (slex->lock_type)
|
switch (slex->lock_type)
|
||||||
|
@@ -382,6 +382,11 @@ static Sys_var_charptr Sys_basedir(
|
|||||||
READ_ONLY GLOBAL_VAR(mysql_home_ptr), CMD_LINE(REQUIRED_ARG, 'b'),
|
READ_ONLY GLOBAL_VAR(mysql_home_ptr), CMD_LINE(REQUIRED_ARG, 'b'),
|
||||||
IN_FS_CHARSET, DEFAULT(0));
|
IN_FS_CHARSET, DEFAULT(0));
|
||||||
|
|
||||||
|
static Sys_var_charptr sys_temporal_current_timestamp(
|
||||||
|
"temporal_current_timestamp", "Default AS OF value for versioned tables",
|
||||||
|
GLOBAL_VAR(temporal_current_timestamp), CMD_LINE(REQUIRED_ARG, 'b'),
|
||||||
|
IN_FS_CHARSET, DEFAULT("now"));
|
||||||
|
|
||||||
static Sys_var_ulonglong Sys_binlog_cache_size(
|
static Sys_var_ulonglong Sys_binlog_cache_size(
|
||||||
"binlog_cache_size", "The size of the transactional cache for "
|
"binlog_cache_size", "The size of the transactional cache for "
|
||||||
"updates to transactional engines for the binary log. "
|
"updates to transactional engines for the binary log. "
|
||||||
|
Reference in New Issue
Block a user