1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

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:
Sergei Golubchik
2017-12-30 13:40:36 +01:00
committed by Aleksey Midenkov
parent b06b5c3eab
commit e6a7457653
35 changed files with 98 additions and 451 deletions

View File

@ -1,3 +1,2 @@
--system-versioning-hide=implicit
--system-versioning-transaction-registry=1
--plugin-load=versioning

View File

@ -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;

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -1 +0,0 @@
--system-versioning-hide=implicit

View File

@ -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;

View File

@ -1 +0,0 @@
--system-versioning-hide=implicit

View File

@ -1,3 +1 @@
--system-versioning-hide=implicit
--system-versioning-alter-history=keep

View File

@ -1 +0,0 @@
--system-versioning-hide=implicit

View File

@ -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;

View File

@ -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;

View File

@ -1 +0,0 @@
--system-versioning-hide=implicit

View File

@ -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;

View File

@ -1,2 +1 @@
--system-versioning-hide=implicit
--partition

View File

@ -1 +0,0 @@
--system-versioning-hide=implicit