SQL: derived, hiding, error messages
Many related changes. Note that AS OF condition must always be pushed down to physical tables, it cannot be applied to a derived or a view. Thus: * no versioning for internal temporary tables, they can never store historical data. * remove special versioning code from mysql_derived_prepare and remove ER_VERS_DERIVED_PROHIBITED - derived can have no historical data and cannot be prohibited for system versioning related reasons. * do not expand select list for derived/views with sys vers fields, derived/views can never have historical data. * remove special invisiblity rules for sys vers fields, they are no longer needed after the previous change * remove system_versioning_hide, it lost the meaning after the previous change. * remove ER_VERS_SYSTEM_TIME_CLASH, it's no "clash", the inner AS OF clause always wins. * non-versioned fields in a historical query reword the warning text, downgrade to note, don't replace values with NULLs
This commit is contained in:
parent
b06b5c3eab
commit
e6a7457653
@ -1230,12 +1230,6 @@ The following options may be given as the first argument:
|
||||
--system-versioning-force
|
||||
Force system versioning for all created tables
|
||||
--system-versioning-hide=name
|
||||
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
|
||||
--system-versioning-innodb-algorithm-simple
|
||||
Use simple algorithm of timestamp handling in InnoDB
|
||||
instead of TRX_SEES
|
||||
@ -1674,7 +1668,6 @@ sync-relay-log-info 10000
|
||||
sysdate-is-now FALSE
|
||||
system-versioning-alter-history ERROR
|
||||
system-versioning-force FALSE
|
||||
system-versioning-hide AUTO
|
||||
system-versioning-innodb-algorithm-simple TRUE
|
||||
system-versioning-transaction-registry FALSE
|
||||
table-cache 431
|
||||
|
@ -4113,20 +4113,6 @@ NUMERIC_BLOCK_SIZE NULL
|
||||
ENUM_VALUE_LIST OFF,ON
|
||||
READ_ONLY NO
|
||||
COMMAND_LINE_ARGUMENT OPTIONAL
|
||||
VARIABLE_NAME SYSTEM_VERSIONING_HIDE
|
||||
SESSION_VALUE AUTO
|
||||
GLOBAL_VALUE AUTO
|
||||
GLOBAL_VALUE_ORIGIN COMPILE-TIME
|
||||
DEFAULT_VALUE AUTO
|
||||
VARIABLE_SCOPE SESSION
|
||||
VARIABLE_TYPE ENUM
|
||||
VARIABLE_COMMENT 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
|
||||
NUMERIC_MIN_VALUE NULL
|
||||
NUMERIC_MAX_VALUE NULL
|
||||
NUMERIC_BLOCK_SIZE NULL
|
||||
ENUM_VALUE_LIST AUTO,IMPLICIT,FULL,NEVER
|
||||
READ_ONLY NO
|
||||
COMMAND_LINE_ARGUMENT REQUIRED
|
||||
VARIABLE_NAME SYSTEM_VERSIONING_INNODB_ALGORITHM_SIMPLE
|
||||
SESSION_VALUE ON
|
||||
GLOBAL_VALUE ON
|
||||
|
@ -5065,20 +5065,6 @@ NUMERIC_BLOCK_SIZE NULL
|
||||
ENUM_VALUE_LIST OFF,ON
|
||||
READ_ONLY NO
|
||||
COMMAND_LINE_ARGUMENT OPTIONAL
|
||||
VARIABLE_NAME SYSTEM_VERSIONING_HIDE
|
||||
SESSION_VALUE AUTO
|
||||
GLOBAL_VALUE AUTO
|
||||
GLOBAL_VALUE_ORIGIN COMPILE-TIME
|
||||
DEFAULT_VALUE AUTO
|
||||
VARIABLE_SCOPE SESSION
|
||||
VARIABLE_TYPE ENUM
|
||||
VARIABLE_COMMENT 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
|
||||
NUMERIC_MIN_VALUE NULL
|
||||
NUMERIC_MAX_VALUE NULL
|
||||
NUMERIC_BLOCK_SIZE NULL
|
||||
ENUM_VALUE_LIST AUTO,IMPLICIT,FULL,NEVER
|
||||
READ_ONLY NO
|
||||
COMMAND_LINE_ARGUMENT REQUIRED
|
||||
VARIABLE_NAME SYSTEM_VERSIONING_INNODB_ALGORITHM_SIMPLE
|
||||
SESSION_VALUE ON
|
||||
GLOBAL_VALUE ON
|
||||
|
@ -1,3 +1,2 @@
|
||||
--system-versioning-hide=implicit
|
||||
--system-versioning-transaction-registry=1
|
||||
--plugin-load=versioning
|
||||
|
@ -135,9 +135,11 @@ delete from t1;
|
||||
insert into t1 values (2);
|
||||
insert into t2 values (10);
|
||||
select * from (select *, t1.sys_trx_end, t1.sys_trx_end as endo from t1) as s0;
|
||||
ERROR HY000: Derived table is prohibited: multiple end system fields `t1.sys_trx_end`, `t1.sys_trx_end` in query!
|
||||
x sys_trx_end endo
|
||||
2 # #
|
||||
select * from (select *, t1.sys_trx_end, t2.sys_trx_start from t1, t2) as s0;
|
||||
ERROR HY000: Derived table is prohibited: system fields from multiple tables `t1`, `t2` in query!
|
||||
x y sys_trx_end sys_trx_start
|
||||
2 10 # #
|
||||
# SYSTEM_TIME propagation from inner to outer
|
||||
select * from (select * from t1 for system_time as of timestamp @t0, t2) as s0;
|
||||
x y
|
||||
@ -147,11 +149,11 @@ x y
|
||||
1 10
|
||||
# leading table selection
|
||||
select * from (select *, t1.sys_trx_end from t2, t1 for system_time as of timestamp @t0) as s2;
|
||||
y x
|
||||
10 1
|
||||
y x sys_trx_end
|
||||
10 1 #
|
||||
with s3 as (select *, t1.sys_trx_end from t2, t1 for system_time as of timestamp @t0) select * from s3;
|
||||
y x
|
||||
10 1
|
||||
y x sys_trx_end
|
||||
10 1 #
|
||||
### VIEW instead of t1
|
||||
set @q= concat("create view vt1 as select * from t1 for system_time as of timestamp '", @t0, "'");
|
||||
prepare q from @q;
|
||||
@ -168,12 +170,12 @@ x y
|
||||
1 10
|
||||
### SYSTEM_TIME clash
|
||||
select * from (select * from t1 for system_time all) for system_time all as dt0;
|
||||
ERROR HY000: SYSTEM_TIME is not allowed outside historical `dt0`
|
||||
ERROR HY000: Table `dt0` is not system-versioned
|
||||
select * from vt1 for system_time all;
|
||||
ERROR HY000: SYSTEM_TIME is not allowed outside historical `vt1`
|
||||
ERROR HY000: Table `vt1` is not system-versioned
|
||||
with dt1 as (select * from t1 for system_time all)
|
||||
select * from dt1 for system_time all;
|
||||
ERROR HY000: SYSTEM_TIME is not allowed outside historical `dt1`
|
||||
ERROR HY000: Table `dt1` is not system-versioned
|
||||
### UNION
|
||||
set @t1= now(6);
|
||||
delete from t2;
|
||||
|
@ -290,7 +290,7 @@ insert into t1(x) values (1);
|
||||
ERROR HY000: Temporal operation requires `mysql.transaction_registry` (@@system_versioning_transaction_registry).
|
||||
set global system_versioning_transaction_registry= on;
|
||||
Warnings:
|
||||
Warning 4143 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
|
||||
Warning 4141 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
|
||||
create or replace table t1 (
|
||||
x int,
|
||||
y int as (x) virtual,
|
||||
|
@ -14,7 +14,7 @@ alter table t drop system versioning, algorithm=inplace;
|
||||
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Not implemented for system-versioned tables. Try ALGORITHM=COPY
|
||||
set global system_versioning_transaction_registry=on;
|
||||
Warnings:
|
||||
Warning 4143 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
|
||||
Warning 4141 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
|
||||
create or replace table t (a int, b int) engine=innodb;
|
||||
alter table t
|
||||
add s bigint unsigned as row start,
|
||||
|
@ -14,62 +14,67 @@ a
|
||||
3
|
||||
select a, b, b+0 from t for system_time as of timestamp now(6);
|
||||
a b b+0
|
||||
1 NULL NULL
|
||||
3 NULL NULL
|
||||
1 2 2
|
||||
3 4 4
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select * from t for system_time as of timestamp now(6);
|
||||
a b
|
||||
1 NULL
|
||||
3 NULL
|
||||
1 2
|
||||
3 4
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select count(*) from t for system_time as of timestamp now(6) group by b;
|
||||
count(*)
|
||||
2
|
||||
1
|
||||
1
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select * from t for system_time as of timestamp now(6) order by b asc;
|
||||
a b
|
||||
1 NULL
|
||||
3 NULL
|
||||
1 2
|
||||
3 4
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select * from t for system_time as of timestamp now(6) order by b desc;
|
||||
a b
|
||||
1 NULL
|
||||
3 NULL
|
||||
3 4
|
||||
1 2
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select * from t for system_time as of timestamp now(6) group by a having a=2;
|
||||
a b
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select * from t for system_time as of timestamp now(6) group by b having b=2;
|
||||
a b
|
||||
1 2
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select a from t for system_time as of timestamp now(6) where b=2;
|
||||
a
|
||||
1
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select a from t for system_time as of timestamp now(6) where b=NULL;
|
||||
a
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select a from t for system_time as of timestamp now(6) where b is NULL;
|
||||
a
|
||||
1
|
||||
3
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select count(*), b from t for system_time as of timestamp now(6) group by b having b=NULL;
|
||||
count(*) b
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select a, b from t;
|
||||
a b
|
||||
1 2
|
||||
@ -81,15 +86,12 @@ b int not null without system versioning
|
||||
insert into t values (1, 2), (3, 4);
|
||||
select * from t for system_time as of timestamp now(6);
|
||||
a b
|
||||
1 NULL
|
||||
3 NULL
|
||||
1 2
|
||||
3 4
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
select * from t for system_time as of timestamp now(6) where b is NULL;
|
||||
a b
|
||||
1 NULL
|
||||
3 NULL
|
||||
Warnings:
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Warning 4111 Attempt to read non-temporal field `b` in historical query
|
||||
Note 4111 Non-versioned field `b` in historical query
|
||||
drop table t;
|
||||
|
@ -306,7 +306,7 @@ x y
|
||||
2 1
|
||||
select * from (select * from t1 for system_time all, t2 for system_time all)
|
||||
for system_time all as t;
|
||||
ERROR HY000: SYSTEM_TIME is not allowed outside historical `t`
|
||||
ERROR HY000: Table `t` is not system-versioned
|
||||
# TRANSACTION/TIMESTAMP specifier in SYSTEM_TIME [MDEV-14645, Issue #396]
|
||||
create or replace table t1 (x int) with system versioning engine myisam;
|
||||
select * from t1 for system_time as of transaction 1;
|
||||
|
@ -359,7 +359,7 @@ x y
|
||||
1 1
|
||||
2 1
|
||||
select * from (select * from t1 for system_time all, t2 for system_time all) for system_time all as t;
|
||||
ERROR HY000: SYSTEM_TIME is not allowed outside historical `t`
|
||||
ERROR HY000: Table `t` is not system-versioned
|
||||
select * from (t1 for system_time all join t2 for system_time all) for system_time all;
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
|
||||
drop view v1;
|
||||
|
@ -47,7 +47,7 @@ emp for system_time from timestamp @ts_1 to timestamp @ts_2 e,
|
||||
dept for system_time from timestamp @ts_1 to timestamp @ts_2 d
|
||||
where d.dept_id = 10
|
||||
and d.dept_id = e.dept_id;
|
||||
emp_id dept_id name salary sys_trx_start sys_trx_end dept_id name sys_trx_start sys_trx_end
|
||||
emp_id dept_id name salary dept_id name
|
||||
set statement system_versioning_asof=@ts_0 for
|
||||
select * from emp e, dept d
|
||||
where d.dept_id = 10
|
||||
|
@ -104,14 +104,10 @@ set system_versioning_asof= DEFAULT;
|
||||
select @@global.system_versioning_asof, @@system_versioning_asof;
|
||||
@@global.system_versioning_asof @@system_versioning_asof
|
||||
DEFAULT DEFAULT
|
||||
show variables where variable_name = "system_versioning_hide";
|
||||
Variable_name Value
|
||||
system_versioning_hide IMPLICIT
|
||||
select * from t for system_time all;
|
||||
a
|
||||
2
|
||||
1
|
||||
set system_versioning_hide= AUTO;
|
||||
select * from t;
|
||||
a
|
||||
2
|
||||
@ -119,39 +115,15 @@ select * from t for system_time as of timestamp current_timestamp(6);
|
||||
a
|
||||
2
|
||||
select * from t for system_time all;
|
||||
a sys_trx_start sys_trx_end
|
||||
2 TIMESTAMP TIMESTAMP
|
||||
1 TIMESTAMP TIMESTAMP
|
||||
select * from t for system_time from '0-0-0' to current_timestamp(6);
|
||||
a sys_trx_start sys_trx_end
|
||||
2 TIMESTAMP TIMESTAMP
|
||||
1 TIMESTAMP TIMESTAMP
|
||||
select * from t for system_time between '0-0-0' and current_timestamp(6);
|
||||
a sys_trx_start sys_trx_end
|
||||
2 TIMESTAMP TIMESTAMP
|
||||
1 TIMESTAMP TIMESTAMP
|
||||
set system_versioning_hide= NEVER;
|
||||
select * from t;
|
||||
a sys_trx_start sys_trx_end
|
||||
2 TIMESTAMP TIMESTAMP
|
||||
set system_versioning_hide= FULL;
|
||||
create or replace table t (
|
||||
x int,
|
||||
st timestamp(6) as row start invisible,
|
||||
en timestamp(6) as row end invisible,
|
||||
period for system_time (st, en))
|
||||
with system versioning;
|
||||
show create table t;
|
||||
Table Create Table
|
||||
t CREATE TABLE `t` (
|
||||
`x` int(11) DEFAULT NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
insert into t values (2);
|
||||
delete from t;
|
||||
select * from t;
|
||||
x
|
||||
select * from t for system_time all;
|
||||
x
|
||||
a
|
||||
2
|
||||
1
|
||||
select * from t for system_time from '0-0-0' to current_timestamp(6);
|
||||
a
|
||||
2
|
||||
1
|
||||
select * from t for system_time between '0-0-0' and current_timestamp(6);
|
||||
a
|
||||
2
|
||||
1
|
||||
drop table t;
|
||||
set system_versioning_hide= IMPLICIT;
|
||||
|
@ -10,7 +10,7 @@ period for system_time (sys_trx_start, sys_trx_end)
|
||||
ERROR HY000: Temporal operation requires `mysql.transaction_registry` (@@system_versioning_transaction_registry).
|
||||
set global system_versioning_transaction_registry= 1;
|
||||
Warnings:
|
||||
Warning 4143 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
|
||||
Warning 4141 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
|
||||
create or replace table t1 (
|
||||
x int,
|
||||
sys_trx_start bigint(20) unsigned as row start invisible,
|
||||
@ -32,7 +32,7 @@ return if(cond = 1, '[CORRECT]', '[INCORRECT]');
|
||||
set @@system_versioning_alter_history=keep;
|
||||
set global system_versioning_transaction_registry=on;
|
||||
Warnings:
|
||||
Warning 4143 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
|
||||
Warning 4141 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
|
||||
create or replace table t1 (x int) engine innodb;
|
||||
insert into t1 values (1);
|
||||
alter table t1
|
||||
|
@ -1 +0,0 @@
|
||||
--system-versioning-hide=implicit
|
@ -99,16 +99,18 @@ delete from t1;
|
||||
insert into t1 values (2);
|
||||
insert into t2 values (10);
|
||||
|
||||
--error ER_VERS_DERIVED_PROHIBITED
|
||||
--replace_column 2 # 3 #
|
||||
select * from (select *, t1.sys_trx_end, t1.sys_trx_end as endo from t1) as s0;
|
||||
--error ER_VERS_DERIVED_PROHIBITED
|
||||
--replace_column 3 # 4 #
|
||||
select * from (select *, t1.sys_trx_end, t2.sys_trx_start from t1, t2) as s0;
|
||||
|
||||
--echo # SYSTEM_TIME propagation from inner to outer
|
||||
select * from (select * from t1 for system_time as of timestamp @t0, t2) as s0;
|
||||
with s1 as (select * from t1 for system_time as of timestamp @t0, t2) select * from s1;
|
||||
--echo # leading table selection
|
||||
--replace_column 3 #
|
||||
select * from (select *, t1.sys_trx_end from t2, t1 for system_time as of timestamp @t0) as s2;
|
||||
--replace_column 3 #
|
||||
with s3 as (select *, t1.sys_trx_end from t2, t1 for system_time as of timestamp @t0) select * from s3;
|
||||
|
||||
--echo ### VIEW instead of t1
|
||||
@ -122,11 +124,11 @@ select * from vt1;
|
||||
select * from (select * from vt1, t2) as s0;
|
||||
|
||||
--echo ### SYSTEM_TIME clash
|
||||
--error ER_VERS_SYSTEM_TIME_CLASH
|
||||
--error ER_VERS_NOT_VERSIONED
|
||||
select * from (select * from t1 for system_time all) for system_time all as dt0;
|
||||
--error ER_VERS_SYSTEM_TIME_CLASH
|
||||
--error ER_VERS_NOT_VERSIONED
|
||||
select * from vt1 for system_time all;
|
||||
--error ER_VERS_SYSTEM_TIME_CLASH
|
||||
--error ER_VERS_NOT_VERSIONED
|
||||
with dt1 as (select * from t1 for system_time all)
|
||||
select * from dt1 for system_time all;
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
--system-versioning-hide=implicit
|
@ -1,3 +1 @@
|
||||
--system-versioning-hide=implicit
|
||||
--system-versioning-alter-history=keep
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
--system-versioning-hide=implicit
|
@ -192,7 +192,7 @@ delete from t1 where x = 3;
|
||||
insert into t2 values (1);
|
||||
select * from t1, t2 for system_time all;
|
||||
|
||||
--error ER_VERS_SYSTEM_TIME_CLASH
|
||||
--error ER_VERS_NOT_VERSIONED
|
||||
select * from (select * from t1 for system_time all, t2 for system_time all)
|
||||
for system_time all as t;
|
||||
|
||||
|
@ -219,7 +219,7 @@ delete from t1 where x = 3;
|
||||
insert into t2 values (1);
|
||||
select * from t1, t2 for system_time all;
|
||||
|
||||
--error ER_VERS_SYSTEM_TIME_CLASH
|
||||
--error ER_VERS_NOT_VERSIONED
|
||||
select * from (select * from t1 for system_time all, t2 for system_time all) for system_time all as t;
|
||||
--error ER_PARSE_ERROR
|
||||
select * from (t1 for system_time all join t2 for system_time all) for system_time all;
|
||||
|
@ -1 +0,0 @@
|
||||
--system-versioning-hide=implicit
|
@ -76,37 +76,12 @@ set global system_versioning_asof= DEFAULT;
|
||||
set system_versioning_asof= DEFAULT;
|
||||
select @@global.system_versioning_asof, @@system_versioning_asof;
|
||||
|
||||
show variables where variable_name = "system_versioning_hide";
|
||||
select * from t for system_time all;
|
||||
|
||||
set system_versioning_hide= AUTO;
|
||||
select * from t;
|
||||
select * from t for system_time as of timestamp current_timestamp(6);
|
||||
--replace_regex /\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d{6}/TIMESTAMP/
|
||||
select * from t for system_time all;
|
||||
--replace_regex /\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d{6}/TIMESTAMP/
|
||||
select * from t for system_time from '0-0-0' to current_timestamp(6);
|
||||
--replace_regex /\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d{6}/TIMESTAMP/
|
||||
select * from t for system_time between '0-0-0' and current_timestamp(6);
|
||||
|
||||
set system_versioning_hide= NEVER;
|
||||
--replace_regex /\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d{6}/TIMESTAMP/
|
||||
select * from t;
|
||||
|
||||
set system_versioning_hide= FULL;
|
||||
create or replace table t (
|
||||
x int,
|
||||
st timestamp(6) as row start invisible,
|
||||
en timestamp(6) as row end invisible,
|
||||
period for system_time (st, en))
|
||||
with system versioning;
|
||||
|
||||
show create table t;
|
||||
insert into t values (2);
|
||||
delete from t;
|
||||
|
||||
select * from t;
|
||||
select * from t for system_time all;
|
||||
|
||||
drop table t;
|
||||
set system_versioning_hide= IMPLICIT;
|
||||
|
@ -1,2 +1 @@
|
||||
--system-versioning-hide=implicit
|
||||
--partition
|
||||
|
@ -1 +0,0 @@
|
||||
--system-versioning-hide=implicit
|
@ -1472,8 +1472,6 @@ public:
|
||||
return flags & VERS_UPDATE_UNVERSIONED_FLAG;
|
||||
}
|
||||
|
||||
bool vers_sys_invisible(THD *thd) const;
|
||||
|
||||
virtual bool vers_trx_id() const
|
||||
{
|
||||
return false;
|
||||
|
11
sql/item.cc
11
sql/item.cc
@ -10632,15 +10632,10 @@ Item *Item_field::vers_transformer(THD *thd, uchar *)
|
||||
field->table->pos_in_table_list &&
|
||||
field->table->pos_in_table_list->vers_conditions)
|
||||
{
|
||||
push_warning_printf(
|
||||
current_thd, Sql_condition::WARN_LEVEL_WARN,
|
||||
ER_NON_VERSIONED_FIELD_IN_VERSIONED_QUERY,
|
||||
ER_THD(current_thd, ER_NON_VERSIONED_FIELD_IN_VERSIONED_QUERY),
|
||||
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
|
||||
ER_NON_VERSIONED_FIELD_IN_HISTORICAL_QUERY,
|
||||
ER_THD(thd, ER_NON_VERSIONED_FIELD_IN_HISTORICAL_QUERY),
|
||||
field_name.str);
|
||||
|
||||
Item *null_item= new (thd->mem_root) Item_null(thd);
|
||||
if (null_item)
|
||||
return null_item;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@ -7828,8 +7828,8 @@ ER_VERS_ENGINE_UNSUPPORTED
|
||||
ER_VERS_RANGE_UNITS_MISMATCH
|
||||
eng "Range units mismatch"
|
||||
|
||||
ER_NON_VERSIONED_FIELD_IN_VERSIONED_QUERY
|
||||
eng "Attempt to read non-temporal field %`s in historical query"
|
||||
ER_NON_VERSIONED_FIELD_IN_HISTORICAL_QUERY
|
||||
eng "Non-versioned field %`s in historical query"
|
||||
|
||||
ER_PARTITION_WRONG_TYPE
|
||||
eng "Wrong partitioning type, expected type: %`s"
|
||||
@ -7861,12 +7861,6 @@ ER_VERS_RANGE_PROHIBITED
|
||||
ER_VERS_VIEW_PROHIBITED
|
||||
eng "Creating VIEW %`s is prohibited!"
|
||||
|
||||
ER_VERS_DERIVED_PROHIBITED
|
||||
eng "Derived table is prohibited!"
|
||||
|
||||
ER_VERS_SYSTEM_TIME_CLASH
|
||||
eng "SYSTEM_TIME is not allowed outside historical %`s"
|
||||
|
||||
ER_VERS_UNUSED_CLAUSE
|
||||
eng "Unused clause: '%s'"
|
||||
|
||||
|
@ -7492,31 +7492,6 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table,
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
bool Field::vers_sys_invisible(THD *thd) const
|
||||
{
|
||||
DBUG_ASSERT(vers_sys_field());
|
||||
enum_sql_command sql_command= thd->lex->sql_command;
|
||||
SELECT_LEX *slex= thd->lex->current_select;
|
||||
ulong vers_hide= thd->variables.vers_hide;
|
||||
DBUG_ASSERT(table);
|
||||
DBUG_ASSERT(table->versioned());
|
||||
DBUG_ASSERT(table->pos_in_table_list);
|
||||
TABLE_LIST *tl= table->pos_in_table_list;
|
||||
vers_system_time_t vers_type= tl->vers_conditions.type;
|
||||
|
||||
return (sql_command == SQLCOM_CREATE_VIEW ||
|
||||
slex->nest_level > 0 ||
|
||||
vers_hide == VERS_HIDE_FULL ||
|
||||
(invisible && (
|
||||
thd->lex->sql_command != SQLCOM_SELECT ||
|
||||
vers_hide == VERS_HIDE_IMPLICIT ||
|
||||
(vers_hide == VERS_HIDE_AUTO && (
|
||||
vers_type == SYSTEM_TIME_UNSPECIFIED ||
|
||||
vers_type == SYSTEM_TIME_AS_OF)))));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Drops in all fields instead of current '*' field
|
||||
|
||||
@ -7646,33 +7621,13 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
|
||||
Field_iterator_natural_join).
|
||||
But view fields can never be invisible.
|
||||
*/
|
||||
if ((field= field_iterator.field()) &&
|
||||
(field->vers_sys_field() ?
|
||||
field->vers_sys_invisible(thd) :
|
||||
field->invisible != VISIBLE))
|
||||
{
|
||||
if ((field= field_iterator.field()) && field->invisible != VISIBLE)
|
||||
continue;
|
||||
}
|
||||
|
||||
Item *item;
|
||||
|
||||
if (!(item= field_iterator.create_item(thd)))
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
if (item->type() == Item::REF_ITEM)
|
||||
{
|
||||
Item *i= item;
|
||||
while (i->type() == Item::REF_ITEM)
|
||||
i= *((Item_ref *)i)->ref;
|
||||
if (i->type() == Item::FIELD_ITEM)
|
||||
{
|
||||
Item_field *f= (Item_field *)i;
|
||||
DBUG_ASSERT(f->field);
|
||||
if (f->field->vers_sys_field() && f->field->vers_sys_invisible(thd))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* cache the table for the Item_fields inserted by expanding stars */
|
||||
if (item->type() == Item::FIELD_ITEM && tables->cacheable_table)
|
||||
((Item_field *)item)->cached_table= tables;
|
||||
|
@ -708,7 +708,6 @@ typedef struct system_variables
|
||||
|
||||
vers_asof_timestamp_t vers_asof_timestamp;
|
||||
my_bool vers_force;
|
||||
ulong vers_hide;
|
||||
my_bool vers_innodb_algorithm_simple;
|
||||
ulong vers_alter_history;
|
||||
} SV;
|
||||
|
@ -734,124 +734,6 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
|
||||
cursor= cursor->next_local)
|
||||
cursor->outer_join|= JOIN_TYPE_OUTER;
|
||||
}
|
||||
|
||||
// System Versioning: fix system fields of versioned derived table
|
||||
if ((thd->stmt_arena->is_stmt_prepare() || !thd->stmt_arena->is_stmt_execute())
|
||||
&& sl->table_list.elements > 0)
|
||||
{
|
||||
// Similar logic as in mysql_create_view()
|
||||
// Leading versioning table detected implicitly (first one selected)
|
||||
TABLE_LIST *impli_table= NULL;
|
||||
// Leading versioning table specified explicitly
|
||||
// (i.e. if at least one system field is selected)
|
||||
TABLE_LIST *expli_table= NULL;
|
||||
LEX_CSTRING impli_start, impli_end;
|
||||
Item_field *expli_start= NULL, *expli_end= NULL;
|
||||
|
||||
for (TABLE_LIST *table= sl->table_list.first; table; table= table->next_local)
|
||||
{
|
||||
if (!table->table || !table->table->versioned())
|
||||
continue;
|
||||
|
||||
const LString_i table_start= table->table->vers_start_field()->field_name;
|
||||
const LString_i table_end= table->table->vers_end_field()->field_name;
|
||||
if (!impli_table)
|
||||
{
|
||||
impli_table= table;
|
||||
impli_start= table_start;
|
||||
impli_end= table_end;
|
||||
}
|
||||
|
||||
/* Implicitly add versioning fields if needed */
|
||||
Item *item;
|
||||
List_iterator_fast<Item> it(sl->item_list);
|
||||
|
||||
DBUG_ASSERT(table->alias);
|
||||
while ((item= it++))
|
||||
{
|
||||
if (item->real_item()->type() != Item::FIELD_ITEM)
|
||||
continue;
|
||||
Item_field *fld= (Item_field*) (item->real_item());
|
||||
if (fld->table_name && 0 != my_strcasecmp(table_alias_charset, table->alias, fld->table_name))
|
||||
continue;
|
||||
DBUG_ASSERT(fld->field_name.str);
|
||||
if (table_start == fld->field_name)
|
||||
{
|
||||
if (expli_start)
|
||||
{
|
||||
my_printf_error(
|
||||
ER_VERS_DERIVED_PROHIBITED,
|
||||
"Derived table is prohibited: multiple start system fields `%s.%s`, `%s.%s` in query!", MYF(0),
|
||||
expli_table->alias,
|
||||
expli_start->field_name.str,
|
||||
table->alias,
|
||||
fld->field_name.str);
|
||||
res= true;
|
||||
goto exit;
|
||||
}
|
||||
if (expli_table)
|
||||
{
|
||||
if (expli_table != table)
|
||||
{
|
||||
expli_table_err:
|
||||
my_printf_error(
|
||||
ER_VERS_DERIVED_PROHIBITED,
|
||||
"Derived table is prohibited: system fields from multiple tables `%s`, `%s` in query!", MYF(0),
|
||||
expli_table->alias,
|
||||
table->alias);
|
||||
res= true;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
expli_table= table;
|
||||
expli_start= fld;
|
||||
impli_end= table_end;
|
||||
}
|
||||
else if (table_end == fld->field_name)
|
||||
{
|
||||
if (expli_end)
|
||||
{
|
||||
my_printf_error(
|
||||
ER_VERS_DERIVED_PROHIBITED,
|
||||
"Derived table is prohibited: multiple end system fields `%s.%s`, `%s.%s` in query!", MYF(0),
|
||||
expli_table->alias,
|
||||
expli_end->field_name.str,
|
||||
table->alias,
|
||||
fld->field_name.str);
|
||||
res= true;
|
||||
goto exit;
|
||||
}
|
||||
if (expli_table)
|
||||
{
|
||||
if (expli_table != table)
|
||||
goto expli_table_err;
|
||||
}
|
||||
else
|
||||
expli_table= table;
|
||||
expli_end= fld;
|
||||
impli_start= table_start;
|
||||
}
|
||||
} // while ((item= it++))
|
||||
} // for (TABLE_LIST *table)
|
||||
|
||||
if (expli_table)
|
||||
impli_table= expli_table;
|
||||
|
||||
if (impli_table)
|
||||
{
|
||||
Query_arena_stmt on_stmt_arena(thd);
|
||||
SELECT_LEX *outer= sl->outer_select();
|
||||
if (outer && outer->table_list.first->vers_conditions)
|
||||
{
|
||||
if (!expli_start && (res= sl->vers_push_field(thd, impli_table, impli_start)))
|
||||
goto exit;
|
||||
if (!expli_end && (res= sl->vers_push_field(thd, impli_table, impli_end)))
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
} // if (sl->table_list.elements > 0)
|
||||
// System Versioning end
|
||||
}
|
||||
|
||||
unit->derived= derived;
|
||||
|
@ -753,7 +753,8 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr
|
||||
{
|
||||
if (table->table && table->table->versioned())
|
||||
versioned_tables++;
|
||||
else if (table->vers_conditions.user_defined())
|
||||
else if (table->vers_conditions.user_defined() &&
|
||||
(table->is_non_derived() || !table->vers_conditions.used))
|
||||
{
|
||||
my_error(ER_VERS_NOT_VERSIONED, MYF(0), table->alias);
|
||||
DBUG_RETURN(-1);
|
||||
@ -819,18 +820,11 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr
|
||||
}
|
||||
#endif
|
||||
|
||||
if (outer_table && table != outer_table) // inner table may be outer in recursive CTE
|
||||
if (outer_table && !vers_conditions)
|
||||
{
|
||||
if (vers_conditions)
|
||||
{
|
||||
my_error(ER_VERS_SYSTEM_TIME_CLASH, MYF(0), outer_table->alias);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// propagate system_time from nearest outer SELECT_LEX
|
||||
vers_conditions= outer_table->vers_conditions;
|
||||
}
|
||||
// propagate system_time from nearest outer SELECT_LEX
|
||||
vers_conditions= outer_table->vers_conditions;
|
||||
outer_table->vers_conditions.used= true;
|
||||
}
|
||||
|
||||
// propagate system_time from sysvar
|
||||
@ -17448,10 +17442,6 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
|
||||
List_iterator_fast<Item> li(fields);
|
||||
Item *item;
|
||||
Field **tmp_from_field=from_field;
|
||||
Field *sys_trx_start= NULL;
|
||||
Field *sys_trx_end= NULL;
|
||||
vers_sys_type_t versioned= VERS_UNDEFINED;
|
||||
|
||||
while ((item=li++))
|
||||
{
|
||||
Item::Type type= item->type();
|
||||
@ -17578,44 +17568,6 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
|
||||
continue; // Some kind of const item
|
||||
}
|
||||
DBUG_ASSERT(!new_field->field_name.str || strlen(new_field->field_name.str) == new_field->field_name.length);
|
||||
|
||||
if (type == Item::FIELD_ITEM || type == Item::REF_ITEM)
|
||||
{
|
||||
if (item->real_item()->type() == Item::FIELD_ITEM)
|
||||
{
|
||||
Item_field *item_field= (Item_field *)item->real_item();
|
||||
Field *field= item_field->field;
|
||||
TABLE_SHARE *s= field->table->s;
|
||||
if (s->versioned)
|
||||
{
|
||||
if (field->flags & VERS_SYS_START_FLAG)
|
||||
{
|
||||
sys_trx_start= new_field;
|
||||
versioned= s->versioned;
|
||||
}
|
||||
else if (field->flags & VERS_SYS_END_FLAG)
|
||||
{
|
||||
sys_trx_end= new_field;
|
||||
versioned= s->versioned;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type == Item::TYPE_HOLDER)
|
||||
{
|
||||
Item_type_holder *ith= (Item_type_holder*)item;
|
||||
if (ith->field_flags() & VERS_SYS_START_FLAG)
|
||||
{
|
||||
sys_trx_start= new_field;
|
||||
goto set_versioned;
|
||||
}
|
||||
else if (ith->field_flags() & VERS_SYS_END_FLAG)
|
||||
{
|
||||
sys_trx_end= new_field;
|
||||
set_versioned:
|
||||
versioned= ith->vers_trx_id() ? VERS_TRX_ID : VERS_TIMESTAMP;
|
||||
}
|
||||
}
|
||||
if (type == Item::SUM_FUNC_ITEM)
|
||||
{
|
||||
Item_sum *agg_item= (Item_sum *) item;
|
||||
@ -17696,20 +17648,6 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
|
||||
total_uneven_bit_length= 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (sys_trx_start && sys_trx_end)
|
||||
{
|
||||
DBUG_ASSERT(versioned);
|
||||
sys_trx_start->flags|= VERS_SYS_START_FLAG;
|
||||
sys_trx_end->flags|= VERS_SYS_END_FLAG;
|
||||
sys_trx_start->invisible= INVISIBLE_SYSTEM;
|
||||
sys_trx_end->invisible= INVISIBLE_SYSTEM;
|
||||
share->versioned= versioned;
|
||||
share->field= table->field;
|
||||
share->row_start_field= sys_trx_start->field_index;
|
||||
share->row_end_field= sys_trx_end->field_index;
|
||||
}
|
||||
|
||||
DBUG_ASSERT(fieldnr == (uint) (reg_field - table->field));
|
||||
DBUG_ASSERT(field_count >= (uint) (reg_field - table->field));
|
||||
field_count= fieldnr;
|
||||
|
@ -2108,7 +2108,6 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
|
||||
TABLE *table= table_list->table;
|
||||
TABLE_SHARE *share= table->s;
|
||||
sql_mode_t sql_mode= thd->variables.sql_mode;
|
||||
ulong vers_hide= thd->variables.vers_hide;
|
||||
bool foreign_db_mode= sql_mode & (MODE_POSTGRESQL | MODE_ORACLE |
|
||||
MODE_MSSQL | MODE_DB2 |
|
||||
MODE_MAXDB | MODE_ANSI);
|
||||
@ -2189,17 +2188,8 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
|
||||
|
||||
uint flags = field->flags;
|
||||
|
||||
if (field->vers_sys_field())
|
||||
{
|
||||
if (vers_hide == VERS_HIDE_FULL || (vers_hide != VERS_HIDE_NEVER &&
|
||||
field->invisible > INVISIBLE_USER))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (field->invisible > INVISIBLE_USER)
|
||||
if (field->invisible > INVISIBLE_USER)
|
||||
continue;
|
||||
|
||||
if (not_the_first_field)
|
||||
packet->append(STRING_WITH_LEN(",\n"));
|
||||
|
||||
@ -2346,12 +2336,8 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
|
||||
for (uint j=0 ; j < key_info->user_defined_key_parts ; j++,key_part++)
|
||||
{
|
||||
Field *field= key_part->field;
|
||||
if (field && field->vers_sys_field())
|
||||
{
|
||||
if (vers_hide == VERS_HIDE_FULL || (field->invisible &&
|
||||
vers_hide != VERS_HIDE_NEVER))
|
||||
continue;
|
||||
}
|
||||
if (field->invisible > INVISIBLE_USER)
|
||||
continue;
|
||||
|
||||
if (j)
|
||||
packet->append(',');
|
||||
@ -2381,21 +2367,26 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
|
||||
hton->index_options);
|
||||
}
|
||||
|
||||
if (table->versioned() && vers_hide != VERS_HIDE_FULL)
|
||||
if (table->versioned())
|
||||
{
|
||||
const Field *fs = table->vers_start_field();
|
||||
const Field *fe = table->vers_end_field();
|
||||
DBUG_ASSERT(fs);
|
||||
DBUG_ASSERT(fe);
|
||||
DBUG_ASSERT(!fs->invisible || fe->invisible);
|
||||
if (fe->invisible < INVISIBLE_SYSTEM || vers_hide == VERS_HIDE_NEVER)
|
||||
if (fs->invisible < INVISIBLE_SYSTEM)
|
||||
{
|
||||
DBUG_ASSERT(fe->invisible < INVISIBLE_SYSTEM);
|
||||
packet->append(STRING_WITH_LEN(",\n PERIOD FOR SYSTEM_TIME ("));
|
||||
append_identifier(thd,packet,fs->field_name.str, fs->field_name.length);
|
||||
packet->append(STRING_WITH_LEN(", "));
|
||||
append_identifier(thd,packet,fe->field_name.str, fe->field_name.length);
|
||||
packet->append(STRING_WITH_LEN(")"));
|
||||
}
|
||||
else
|
||||
{
|
||||
DBUG_ASSERT(fs->invisible == INVISIBLE_SYSTEM);
|
||||
DBUG_ASSERT(fe->invisible == INVISIBLE_SYSTEM);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2436,10 +2427,8 @@ 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() && vers_hide != VERS_HIDE_FULL)
|
||||
{
|
||||
if (table->versioned())
|
||||
packet->append(STRING_WITH_LEN(" WITH SYSTEM VERSIONING"));
|
||||
}
|
||||
|
||||
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
||||
{
|
||||
@ -5027,9 +5016,6 @@ public:
|
||||
static bool get_all_archive_tables(THD *thd,
|
||||
Dynamic_array<String> &all_archive_tables)
|
||||
{
|
||||
if (thd->variables.vers_hide == VERS_HIDE_NEVER)
|
||||
return false;
|
||||
|
||||
if (thd->variables.vers_alter_history != VERS_ALTER_HISTORY_SURVIVE)
|
||||
return false;
|
||||
|
||||
|
@ -748,7 +748,7 @@ void vers_select_conds_t::init(vers_system_time_t t, vers_sys_type_t u_start,
|
||||
unit_end= u_end;
|
||||
start= fix_dec(s);
|
||||
end= fix_dec(e);
|
||||
from_query= false;
|
||||
used= from_query= false;
|
||||
}
|
||||
|
||||
Item *vers_select_conds_t::fix_dec(Item *item)
|
||||
|
@ -400,16 +400,6 @@ static Sys_var_mybool Sys_vers_force(
|
||||
"system_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", NULL};
|
||||
static Sys_var_enum Sys_vers_hide(
|
||||
"system_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(REQUIRED_ARG),
|
||||
vers_hide_keywords, DEFAULT(VERS_HIDE_AUTO));
|
||||
|
||||
static Sys_var_mybool Sys_vers_innodb_algorithm_simple(
|
||||
"system_versioning_innodb_algorithm_simple",
|
||||
"Use simple algorithm of timestamp handling in InnoDB instead of TRX_SEES",
|
||||
|
@ -1870,13 +1870,14 @@ struct vers_select_conds_t
|
||||
vers_system_time_t type;
|
||||
vers_sys_type_t unit_start, unit_end;
|
||||
bool from_query:1;
|
||||
bool used:1;
|
||||
Item *start, *end;
|
||||
|
||||
void empty()
|
||||
{
|
||||
type= SYSTEM_TIME_UNSPECIFIED;
|
||||
unit_start= unit_end= VERS_UNDEFINED;
|
||||
from_query= false;
|
||||
used= from_query= false;
|
||||
start= end= NULL;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user