diff --git a/mysql-test/suite/versioning/common.inc b/mysql-test/suite/versioning/common.inc index ec3c5ad04ed..4324dd27cd8 100644 --- a/mysql-test/suite/versioning/common.inc +++ b/mysql-test/suite/versioning/common.inc @@ -22,44 +22,13 @@ begin from mysql.transaction_registry; end~~ -create function if not exists default_engine() -returns varchar(255) -deterministic -begin - declare e varchar(255); - select engine from information_schema.engines where support='DEFAULT' into e; - return e; -end~~ - -create function if not exists non_default_engine() -returns varchar(255) -deterministic -begin - if default_engine() = 'InnoDB' then - return 'MyISAM'; - end if; - return 'InnoDB'; -end~~ - -create function if not exists sys_datatype(engine varchar(255)) -returns varchar(255) -deterministic -begin - if engine = 'InnoDB' then - return 'bigint(20) unsigned'; - elseif engine = 'MyISAM' then - return 'timestamp(6)'; - end if; - return NULL; -end~~ - create function if not exists sys_commit_ts(sys_field varchar(255)) returns varchar(255) deterministic begin - if default_engine() = 'InnoDB' then + if @@default_storage_engine = 'InnoDB' then return concat('vtq_commit_ts(', sys_field, ')'); - elseif default_engine() = 'MyISAM' then + elseif @@default_storage_engine = 'MyISAM' then return sys_field; end if; return NULL; @@ -92,19 +61,11 @@ begin end~~ delimiter ;~~ -let $default_engine= `select default_engine()`; -let $non_default_engine= `select non_default_engine()`; -let $sys_datatype= timestamp(6); +let $default_engine= `select @@default_storage_engine`; +let $non_default_engine= `select if(@@default_storage_engine = 'InnoDB', 'MyISAM', 'InnoDB')`; let $sys_datatype_expl= timestamp(6); -let $sys_datatype_uc= TIMESTAMP(6); let $sys_datatype_expl_uc= TIMESTAMP(6); - -let $non_sys_datatype= `select sys_datatype(non_default_engine())`; -let $non_sys_datatype_uc= `select upper(sys_datatype(non_default_engine()))`; -let $sys_datatype_null= $sys_datatype NULL DEFAULT NULL; -let $sys_datatype_default_null= $sys_datatype DEFAULT NULL; -let $sys_datatype_not_null= $sys_datatype NOT NULL DEFAULT '0000-00-00 00:00:00.000000'; -let $non_sys_datatype_null= $non_sys_datatype NULL; +let $sys_datatype_max= TIMESTAMP'2038-01-19 03:14:07.999999'; if ($MTR_COMBINATION_MYISAM) { @@ -114,5 +75,6 @@ if ($MTR_COMBINATION_TRX_ID) { let $sys_datatype_expl= bigint(20) unsigned; let $sys_datatype_expl_uc= BIGINT(20) UNSIGNED; + let $sys_datatype_max= 18446744073709551615; } --enable_query_log diff --git a/mysql-test/suite/versioning/common_finish.inc b/mysql-test/suite/versioning/common_finish.inc index f8f39d8b4e1..6894267f353 100644 --- a/mysql-test/suite/versioning/common_finish.inc +++ b/mysql-test/suite/versioning/common_finish.inc @@ -1,10 +1,7 @@ --disable_query_log drop procedure verify_vtq; drop procedure verify_vtq_dummy; -drop function default_engine; -drop function non_default_engine; drop function sys_commit_ts; -drop function sys_datatype; drop procedure concat_exec2; drop procedure concat_exec3; --enable_query_log diff --git a/mysql-test/suite/versioning/r/auto_increment.result b/mysql-test/suite/versioning/r/auto_increment.result index 1f43595848b..8ff1bed8fe3 100644 --- a/mysql-test/suite/versioning/r/auto_increment.result +++ b/mysql-test/suite/versioning/r/auto_increment.result @@ -1,26 +1,15 @@ -create procedure test_01( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat(' - create table t1( - id int unsigned auto_increment primary key, - x int unsigned, - y int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; -set @str= concat(' - create table t2( - id int unsigned auto_increment primary key, - x int unsigned, - y int unsigned) - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; +create table t1( +id int unsigned auto_increment primary key, +x int unsigned, +y int unsigned, +sys_start SYS_DATATYPE as row start invisible, +sys_end SYS_DATATYPE as row end invisible, +period for system_time (sys_start, sys_end)) +with system versioning; +create table t2( +id int unsigned auto_increment primary key, +x int unsigned, +y int unsigned); insert into t1(x, y) values(1, 11); insert into t2(x, y) values(1, 11); insert into t1(x, y) values(2, 12); @@ -40,80 +29,37 @@ insert into t2(x, y) values(8, 18); insert into t1(x, y) values(9, 19); insert into t2(x, y) values(9, 19); select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner join t2 on t1.id = t2.id; +A x y x y +1 1 11 1 11 +1 2 12 2 12 +1 3 13 3 13 +1 4 14 4 14 +1 5 15 5 15 +1 6 16 6 16 +1 7 17 7 17 +1 8 18 8 18 +1 9 19 9 19 delete from t1 where x = 2; delete from t2 where x = 2; select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner join t2 on t1.id = t2.id; +A x y x y +1 1 11 1 11 +1 3 13 3 13 +1 4 14 4 14 +1 5 15 5 15 +1 6 16 6 16 +1 7 17 7 17 +1 8 18 8 18 +1 9 19 9 19 delete from t1 where x > 7; delete from t2 where x > 7; select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner join t2 on t1.id = t2.id; +A x y x y +1 1 11 1 11 +1 3 13 3 13 +1 4 14 4 14 +1 5 15 5 15 +1 6 16 6 16 +1 7 17 7 17 drop table t1; drop table t2; -end~~ -call test_01('timestamp(6)', 'myisam', 'sys_end'); -A x y x y -1 1 11 1 11 -1 2 12 2 12 -1 3 13 3 13 -1 4 14 4 14 -1 5 15 5 15 -1 6 16 6 16 -1 7 17 7 17 -1 8 18 8 18 -1 9 19 9 19 -A x y x y -1 1 11 1 11 -1 3 13 3 13 -1 4 14 4 14 -1 5 15 5 15 -1 6 16 6 16 -1 7 17 7 17 -1 8 18 8 18 -1 9 19 9 19 -A x y x y -1 1 11 1 11 -1 3 13 3 13 -1 4 14 4 14 -1 5 15 5 15 -1 6 16 6 16 -1 7 17 7 17 -call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -A x y x y -1 1 11 1 11 -1 2 12 2 12 -1 3 13 3 13 -1 4 14 4 14 -1 5 15 5 15 -1 6 16 6 16 -1 7 17 7 17 -1 8 18 8 18 -1 9 19 9 19 -A x y x y -1 1 11 1 11 -1 3 13 3 13 -1 4 14 4 14 -1 5 15 5 15 -1 6 16 6 16 -1 7 17 7 17 -1 8 18 8 18 -1 9 19 9 19 -A x y x y -1 1 11 1 11 -1 3 13 3 13 -1 4 14 4 14 -1 5 15 5 15 -1 6 16 6 16 -1 7 17 7 17 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 -3 1 1 1 1 -4 1 1 1 1 -5 1 1 1 1 -6 1 1 1 1 -7 1 1 1 1 -8 1 1 1 1 -9 1 1 1 1 -10 1 1 1 1 -11 1 1 1 1 -drop procedure test_01; diff --git a/mysql-test/suite/versioning/r/create.result b/mysql-test/suite/versioning/r/create.result index 7fe1db5964f..871ba3a928c 100644 --- a/mysql-test/suite/versioning/r/create.result +++ b/mysql-test/suite/versioning/r/create.result @@ -85,22 +85,22 @@ t1 CREATE TABLE `t1` ( ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING create or replace table t1 ( x3 int unsigned, -Sys_start SYS_DATATYPE as row start invisible, -Sys_end SYS_DATATYPE as row end invisible, +Sys_start timestamp(6) as row start invisible, +Sys_end timestamp(6) as row end invisible, period for system_time (x, Sys_end) ) with system versioning; ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end` create or replace table t1 ( x4 int unsigned, -Sys_start SYS_DATATYPE as row start invisible, -Sys_end2 SYS_DATATYPE as row end invisible, +Sys_start timestamp(6) as row start invisible, +Sys_end2 timestamp(6) as row end invisible, period for system_time (Sys_start, Sys_end) ) with system versioning; ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end2` create or replace table t1 ( x5 int unsigned, -Sys_start SYS_DATATYPE as row start invisible, -Sys_end SYS_DATATYPE as row end invisible, +Sys_start timestamp(6) as row start invisible, +Sys_end timestamp(6) as row end invisible, period for system_time (Sys_start, x) ) with system versioning; ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end` @@ -111,29 +111,29 @@ period for system_time (Sys_start, Sys_end) ERROR HY000: Wrong parameters for `t1`: missing 'AS ROW START' create or replace table t1 ( x7 int unsigned, -Sys_start SYS_DATATYPE as row start invisible, -Sys_end SYS_DATATYPE as row end invisible, +Sys_start timestamp(6) as row start invisible, +Sys_end timestamp(6) as row end invisible, period for system_time (Sys_start, Sys_end) ); ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING' create or replace table t1 ( x8 int unsigned, -Sys_start SYS_DATATYPE as row start invisible, -Sys_end SYS_DATATYPE as row end invisible, +Sys_start timestamp(6) as row start invisible, +Sys_end timestamp(6) as row end invisible, period for system_time (sys_insert, sys_remove) ) with system versioning; ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end` create or replace table t1 ( x9 int unsigned, -Sys_start SYS_DATATYPE as row start invisible, -Sys_end SYS_DATATYPE as row end invisible, +Sys_start timestamp(6) as row start invisible, +Sys_end timestamp(6) as row end invisible, period for system_time (Sys_start, Sys_end) ); ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING' create or replace table t1 ( x10 int unsigned, -Sys_start SYS_DATATYPE as row start invisible, -Sys_end SYS_DATATYPE as row end invisible, +Sys_start timestamp(6) as row start invisible, +Sys_end timestamp(6) as row end invisible, period for system_time (Sys_start, Sys_start) ); ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING' @@ -247,8 +247,8 @@ tt1 CREATE TEMPORARY TABLE `tt1` ( create or replace table t1 (x23 int) with system versioning; create or replace table t0( y int, -st SYS_DATATYPE as row start, -en SYS_DATATYPE as row end, +st timestamp(6) as row start, +en timestamp(6) as row end, period for system_time (st, en) ) with system versioning; ## For non-versioned table: @@ -267,8 +267,8 @@ show create table t3; Table Create Table t3 CREATE TABLE `t3` ( `y` int(11) DEFAULT NULL, - `st` SYS_DATATYPE, - `en` SYS_DATATYPE + `st` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000', + `en` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 ## For versioned table insert into t1 values (1); @@ -293,8 +293,8 @@ show create table t3; Table Create Table t3 CREATE TABLE `t3` ( `y` int(11) DEFAULT NULL, - `st` SYS_DATATYPE, - `en` SYS_DATATYPE + `st` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000', + `en` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING select * from t3 where y > 2; y st en @@ -303,16 +303,16 @@ y 2 ### 3. source and target table with visible system fields create or replace table t3 ( -st SYS_DATATYPE as row start invisible, -en SYS_DATATYPE as row end invisible, +st timestamp(6) as row start invisible, +en timestamp(6) as row end invisible, period for system_time (st, en) ) with system versioning as select * from t0; show create table t3; Table Create Table t3 CREATE TABLE `t3` ( `y` int(11) DEFAULT NULL, - `st` SYS_DATATYPE GENERATED ALWAYS AS ROW START INVISIBLE, - `en` SYS_DATATYPE GENERATED ALWAYS AS ROW END INVISIBLE, + `st` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE, + `en` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE, PERIOD FOR SYSTEM_TIME (`st`, `en`) ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING select y from t3; @@ -424,8 +424,8 @@ ERROR HY000: Duplicate ROW END column `Sys_end` create or replace table t1 (x30 int) with system versioning; create or replace table t2 ( y int, -st SYS_DATATYPE as row start invisible, -en SYS_DATATYPE as row end invisible, +st timestamp(6) as row start invisible, +en timestamp(6) as row end invisible, period for system_time (st, en) ) with system versioning; create or replace table t3 @@ -435,13 +435,13 @@ Table Create Table t3 CREATE TABLE `t3` ( `x30` int(11) DEFAULT NULL, `y` int(11) DEFAULT NULL, - `st` SYS_DATATYPE NOT NULL INVISIBLE DEFAULT '0000-00-00 00:00:00.000000', - `en` SYS_DATATYPE NOT NULL INVISIBLE DEFAULT '0000-00-00 00:00:00.000000' + `st` timestamp(6) NOT NULL INVISIBLE DEFAULT '0000-00-00 00:00:00.000000', + `en` timestamp(6) NOT NULL INVISIBLE DEFAULT '0000-00-00 00:00:00.000000' ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 create or replace table t3 ( y int, -st SYS_DATATYPE as row start invisible, -en SYS_DATATYPE as row end invisible, +st timestamp(6) as row start invisible, +en timestamp(6) as row end invisible, period for system_time (st, en) ) with system versioning as select x30, y, row_start, row_end, st, en from t1, t2; @@ -450,8 +450,8 @@ Table Create Table t3 CREATE TABLE `t3` ( `x30` int(11) DEFAULT NULL, `y` int(11) DEFAULT NULL, - `st` SYS_DATATYPE GENERATED ALWAYS AS ROW START INVISIBLE, - `en` SYS_DATATYPE GENERATED ALWAYS AS ROW END INVISIBLE, + `st` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE, + `en` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE, PERIOD FOR SYSTEM_TIME (`st`, `en`) ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING # MDEV-14828 Server crashes in JOIN::prepare / setup_fields on 2nd execution of PS [#437] diff --git a/mysql-test/suite/versioning/r/delete.result b/mysql-test/suite/versioning/r/delete.result index 983df50d676..faf8bf6176f 100644 --- a/mysql-test/suite/versioning/r/delete.result +++ b/mysql-test/suite/versioning/r/delete.result @@ -1,17 +1,9 @@ -create or replace procedure test_01( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat(' - create or replace table t1( - XNo int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; +create or replace table t1( +XNo int unsigned, +sys_start SYS_DATATYPE as row start invisible, +sys_end SYS_DATATYPE as row end invisible, +period for system_time (sys_start, sys_end)) +with system versioning; insert into t1(XNo) values(0); insert into t1(XNo) values(1); insert into t1(XNo) values(2); @@ -22,291 +14,98 @@ insert into t1(XNo) values(6); insert into t1(XNo) values(7); insert into t1(XNo) values(8); insert into t1(XNo) values(9); -set @str= concat('select XNo, ', -fields, " < '2038-01-19 03:14:07' - from t1 for system_time - between timestamp '0000-0-0 0:0:0' - and timestamp '2038-01-19 04:14:07'"); -prepare stmt from @str; execute stmt; +select XNo, sys_end < MAXVAL from t1 for system_time all; +XNo sys_end < MAXVAL +0 0 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 delete from t1 where XNo = 0; -select "Deleted 0"; -execute stmt; delete from t1 where XNo = 1; -select "Deleted 1"; -execute stmt; delete from t1 where XNo > 5; -select "Deleted >5"; create view vt1 as select XNo from t1; select XNo as XNo_vt1 from vt1; +XNo_vt1 +2 +3 +4 +5 delete from vt1 where XNo = 3; -select "Deleted from VIEW 3"; select XNo as XNo_vt1 from vt1; -execute stmt; drop prepare stmt; +XNo_vt1 +2 +4 +5 drop view vt1; drop table t1; -end~~ -create or replace procedure test_02( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat('create or replace table t1 ( - x int, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; +create or replace table t1( +x int, +sys_start SYS_DATATYPE as row start invisible, +sys_end SYS_DATATYPE as row end invisible, +period for system_time (sys_start, sys_end)) +with system versioning; insert into t1(x) values (1); select sys_start into @sys_start from t1; delete from t1; select * from t1; -select x = 1 as A, sys_start = @sys_start as B, sys_end > sys_start as C -from t1 for system_time all; +x +select x = 1 as A, sys_start = @sys_start as B, sys_end > sys_start as C from t1 for system_time all; +A B C +1 1 1 drop table t1; -end~~ -create or replace procedure test_03( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str0= concat('( - x int, - y int, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); -set @str= concat('create or replace table t1', @str0); -prepare stmt from @str; execute stmt; drop prepare stmt; -set @str= concat('create or replace table t2', @str0); -prepare stmt from @str; execute stmt; drop prepare stmt; +create or replace table t1( +x int, +y int, +sys_start SYS_DATATYPE as row start invisible, +sys_end SYS_DATATYPE as row end invisible, +period for system_time (sys_start, sys_end)) +with system versioning; +create or replace table t2 like t1; insert into t1(x, y) values (1, 1), (2, 2), (3, 3), (14, 4); insert into t2(x, y) values (11, 1), (12, 2), (13, 32), (14, 4); delete t1, t2 from t1 join t2 where t1.y = 3 and t2.y = 32; select x as t1_x from t1; +t1_x +1 +2 +14 select x as t2_x from t2; +t2_x +11 +12 +14 delete t1, t2 from t1 join t2 where t1.x = t2.x; select x as t1_x from t1; +t1_x +1 +2 select x as t2_x from t2; +t2_x +11 +12 select x as t1_x_all from t1 for system_time all; +t1_x_all +1 +2 +3 +14 select x as t2_x_all from t2 for system_time all; +t2_x_all +11 +12 +13 +14 drop table t1; drop table t2; -end~~ # Basic + delete from view -call test_01('timestamp(6)', 'myisam', 'sys_end'); -XNo sys_end < '2038-01-19 03:14:07' -0 0 -1 0 -2 0 -3 0 -4 0 -5 0 -6 0 -7 0 -8 0 -9 0 -Deleted 0 -Deleted 0 -XNo sys_end < '2038-01-19 03:14:07' -0 1 -1 0 -2 0 -3 0 -4 0 -5 0 -6 0 -7 0 -8 0 -9 0 -Deleted 1 -Deleted 1 -XNo sys_end < '2038-01-19 03:14:07' -0 1 -1 1 -2 0 -3 0 -4 0 -5 0 -6 0 -7 0 -8 0 -9 0 -Deleted >5 -Deleted >5 -XNo_vt1 -2 -3 -4 -5 -Deleted from VIEW 3 -Deleted from VIEW 3 -XNo_vt1 -2 -4 -5 -XNo sys_end < '2038-01-19 03:14:07' -0 1 -1 1 -2 0 -3 1 -4 0 -5 0 -6 1 -7 1 -8 1 -9 1 -call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -XNo vtq_commit_ts(sys_end) < '2038-01-19 03:14:07' -0 0 -1 0 -2 0 -3 0 -4 0 -5 0 -6 0 -7 0 -8 0 -9 0 -Deleted 0 -Deleted 0 -XNo vtq_commit_ts(sys_end) < '2038-01-19 03:14:07' -0 1 -1 0 -2 0 -3 0 -4 0 -5 0 -6 0 -7 0 -8 0 -9 0 -Deleted 1 -Deleted 1 -XNo vtq_commit_ts(sys_end) < '2038-01-19 03:14:07' -0 1 -1 1 -2 0 -3 0 -4 0 -5 0 -6 0 -7 0 -8 0 -9 0 -Deleted >5 -Deleted >5 -XNo_vt1 -2 -3 -4 -5 -Deleted from VIEW 3 -Deleted from VIEW 3 -XNo_vt1 -2 -4 -5 -XNo vtq_commit_ts(sys_end) < '2038-01-19 03:14:07' -0 1 -1 1 -2 0 -3 1 -4 0 -5 0 -6 1 -7 1 -8 1 -9 1 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 -3 1 1 1 1 -4 1 1 1 1 -5 1 1 1 1 -6 1 1 1 1 -7 1 1 1 1 -8 1 1 1 1 -9 1 1 1 1 -10 1 1 1 1 -11 1 1 1 1 -12 1 1 1 1 -13 1 1 1 1 -14 1 1 1 1 # Check sys_start, sys_end -call test_02('timestamp(6)', 'myisam', 'sys_end'); -x -A B C -1 1 1 -call test_02('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -x -A B C -1 1 1 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 # Multi-delete -call test_03('timestamp(6)', 'myisam', 'sys_end'); -t1_x -1 -2 -14 -t2_x -11 -12 -14 -t1_x -1 -2 -t2_x -11 -12 -t1_x_all -1 -2 -3 -14 -t2_x_all -11 -12 -13 -14 -call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -t1_x -1 -2 -14 -t2_x -11 -12 -14 -t1_x -1 -2 -t2_x -11 -12 -t1_x_all -1 -2 -3 -14 -t2_x_all -11 -12 -13 -14 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 -3 1 1 1 1 -4 1 1 1 1 # Update + delete create or replace table t1 (x int) with system versioning; insert into t1 values (1); diff --git a/mysql-test/suite/versioning/r/insert.result b/mysql-test/suite/versioning/r/insert.result index 7df786c45d1..01d829d3430 100644 --- a/mysql-test/suite/versioning/r/insert.result +++ b/mysql-test/suite/versioning/r/insert.result @@ -1,379 +1,112 @@ -create procedure test_01( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat(' - create table t1( - x int unsigned, - y int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; +create or replace table t1( +x int unsigned, +y int unsigned, +sys_start SYS_DATATYPE as row start invisible, +sys_end SYS_DATATYPE as row end invisible, +period for system_time (sys_start, sys_end)) +with system versioning; insert into t1(x, y) values(3, 4); -insert delayed into t1(x, y) values(2, 3); +insert into t1(x, y) values(2, 3); insert into t1 values(40, 33); -set @str= concat('select x, y, ', fields, ' from t1'); -prepare stmt from @str; execute stmt; drop prepare stmt; -drop table t1; -end~~ -create procedure test_02( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat(' - create table t1( - id int unsigned auto_increment primary key, - x int unsigned, - y int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; +select x, y, sys_end < MAXVAL from t1; +x y sys_end < MAXVAL +3 4 0 +2 3 0 +40 33 0 +create or replace table t1( +id int unsigned auto_increment primary key, +x int unsigned, +y int unsigned, +sys_start SYS_DATATYPE as row start invisible, +sys_end SYS_DATATYPE as row end invisible, +period for system_time (sys_start, sys_end)) +with system versioning; insert into t1(x, y) values(33, 44); insert into t1(id, x, y) values(20, 33, 44); insert into t1 values(40, 33, 44); -set @str= concat('select id, x, y, ', fields, ' from t1'); -prepare stmt from @str; execute stmt; drop prepare stmt; -drop table t1; -end~~ -create procedure test_03( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat(' - create table t1( - x int unsigned, - y int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; +select id, x, y, sys_end < MAXVAL from t1; +id x y sys_end < MAXVAL +1 33 44 0 +20 33 44 0 +40 33 44 0 +create or replace table t1( +x int unsigned, +y int unsigned, +sys_start SYS_DATATYPE as row start invisible, +sys_end SYS_DATATYPE as row end invisible, +period for system_time (sys_start, sys_end)) +with system versioning; create view vt1_1 as select x, y from t1; insert into t1(x, y) values(8001, 9001); insert into vt1_1(x, y) values(1001, 2001); insert into vt1_1 values(1002, 2002); -set @str= concat('select x, y, ', fields, ' from t1'); -prepare stmt from @str; execute stmt; drop prepare stmt; +select x, y, sys_end < MAXVAL from t1; +x y sys_end < MAXVAL +8001 9001 0 +1001 2001 0 +1002 2002 0 select x, y from vt1_1; -end~~ -create procedure test_04( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat(' - create table t1( - id bigint primary key, - a int, - b int) - with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; +x y +8001 9001 +1001 2001 +1002 2002 +drop view vt1_1; +create or replace table t1( id bigint primary key, a int, b int) with system versioning; insert into t1 values(1, 1, 1); select row_start, row_end from t1 into @sys_start, @sys_end; select id, a, b from t1; +id a b +1 1 1 insert into t1 values(2, 2, 2); select id, a, b, row_start > @sys_start as C, row_end = @sys_end as D from t1 where id = 2; -drop table t1; -end~~ -create procedure test_05( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat('( - x int unsigned, - y int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); -set @str2= concat('create table t1', @str); -prepare stmt from @str2; execute stmt; drop prepare stmt; -set @str2= concat('create table t2', @str); -prepare stmt from @str2; execute stmt; drop prepare stmt; -insert into t1(x, y) values -(1, 1000), -(2, 2000), -(3, 3000), -(4, 4000), -(5, 5000), -(6, 6000), -(7, 7000), -(8, 8000), -(9, 9000); -delete from t1 where x >= 1; -insert into t1(x, y) values -(1, 1001), -(2, 2001), -(3, 3001), -(4, 4001), -(5, 5001), -(6, 6001); -insert into t1(x, y, sys_start) values -(7, 7001, DEFAULT); -insert into t1(x, y, sys_end) values -(8, 8001, DEFAULT); -insert into t1(x, y, sys_start, sys_end) values -(9, 9001, DEFAULT, DEFAULT); -insert into t2 select x, y from t1 for system_time between timestamp '0000-0-0 0:0:0' and timestamp '9999-1-1 0:0:0'; -select x, y from t1; -select x, y from t2; -drop table t1; -drop table t2; -end~~ -call test_01('timestamp(6)', 'myisam', 'sys_end'); -x y sys_end -3 4 2038-01-19 03:14:07.999999 -2 3 2038-01-19 03:14:07.999999 -40 33 2038-01-19 03:14:07.999999 -call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -x y vtq_commit_ts(sys_end) -3 4 2038-01-19 03:14:07.999999 -2 3 2038-01-19 03:14:07.999999 -40 33 2038-01-19 03:14:07.999999 -call test_02('timestamp(6)', 'myisam', 'sys_end'); -id x y sys_end -1 33 44 2038-01-19 03:14:07.999999 -20 33 44 2038-01-19 03:14:07.999999 -40 33 44 2038-01-19 03:14:07.999999 -call test_02('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -id x y vtq_commit_ts(sys_end) -1 33 44 2038-01-19 03:14:07.999999 -20 33 44 2038-01-19 03:14:07.999999 -40 33 44 2038-01-19 03:14:07.999999 -call test_03('timestamp(6)', 'myisam', 'sys_end'); -x y sys_end -8001 9001 2038-01-19 03:14:07.999999 -1001 2001 2038-01-19 03:14:07.999999 -1002 2002 2038-01-19 03:14:07.999999 -x y -8001 9001 -1001 2001 -1002 2002 -drop table t1; -drop view vt1_1; -call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -x y vtq_commit_ts(sys_end) -8001 9001 2038-01-19 03:14:07.999999 -1001 2001 2038-01-19 03:14:07.999999 -1002 2002 2038-01-19 03:14:07.999999 -x y -8001 9001 -1001 2001 -1002 2002 -drop table t1; -drop view vt1_1; -call test_04('timestamp(6)', 'myisam', 'sys_end'); -id a b -1 1 1 id a b C D 2 2 2 1 1 -call test_04('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -id a b -1 1 1 -id a b C D -2 2 2 1 1 -call test_05('timestamp(6)', 'myisam', 'sys_end'); -x y -1 1001 -2 2001 -3 3001 -4 4001 -5 5001 -6 6001 -7 7001 -8 8001 -9 9001 -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8000 -9 9000 -1 1001 -2 2001 -3 3001 -4 4001 -5 5001 -6 6001 -7 7001 -8 8001 -9 9001 -call test_05('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -x y -1 1001 -2 2001 -3 3001 -4 4001 -5 5001 -6 6001 -7 7001 -8 8001 -9 9001 -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8000 -9 9000 -1 1001 -2 2001 -3 3001 -4 4001 -5 5001 -6 6001 -7 7001 -8 8001 -9 9001 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 -3 1 1 1 1 -4 1 1 1 1 -5 1 1 1 1 -6 1 1 1 1 -7 1 1 1 1 -8 1 1 1 1 -9 1 1 1 1 -10 1 1 1 1 -11 1 1 1 1 -12 1 1 1 1 -13 1 1 1 1 -14 1 1 1 1 -15 1 1 1 1 -16 1 1 1 1 -create table t1( +drop table t1; +create or replace table t1( x int unsigned, -sys_start bigint unsigned as row start invisible, -sys_end bigint unsigned as row end invisible, +y int unsigned, +sys_start SYS_DATATYPE as row start invisible, +sys_end SYS_DATATYPE as row end invisible, period for system_time (sys_start, sys_end)) -with system versioning engine=innodb; -create table t2(x int unsigned) engine=innodb; -start transaction; -insert into t1(x) values(1); -commit; -call verify_vtq; -No A B C D -1 1 1 1 1 -start transaction; -insert into t2(x) values(1); -savepoint a; -insert into t1(x) values(1); -rollback to a; -commit; -call verify_vtq; -No A B C D -insert into t2(x) values (1); -create or replace table t1 ( -x int, -y int as (x) virtual, -sys_trx_start bigint unsigned as row start invisible, -sys_trx_end bigint unsigned as row end invisible, -period for system_time (sys_trx_start, sys_trx_end) -) engine=innodb with system versioning; -insert into t1 values (1, null); -update t1 set x= x + 1; -select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_time all; -x y current -2 2 1 -1 1 0 -create or replace table t1 ( -x int, -row_start timestamp(6) as row start invisible, -row_end timestamp(6) as row end invisible, -period for system_time (row_start, row_end) -) with system versioning; -insert into t1 values (1), (2); -insert into t1 (row_start) select row_end from t1; -ERROR HY000: The value specified for generated column 'row_start' in table 't1' ignored -set sql_mode=''; -insert into t1 (row_start, row_end) values (DEFAULT, 1); -Warnings: -Warning 1906 The value specified for generated column 'row_end' in table 't1' ignored -set sql_mode=default; -select @@sql_mode into @saved_mode; -set sql_mode= ''; -insert into t1 (x, row_start, row_end) values (3, 4, 5); -Warnings: -Warning 1906 The value specified for generated column 'row_start' in table 't1' ignored -Warning 1906 The value specified for generated column 'row_end' in table 't1' ignored -set sql_mode= @saved_mode; -insert into t1 (row_start, row_end) values (DEFAULT, DEFAULT); -select * from t1; -x -1 -2 -NULL -3 -NULL -# MDEV-14792 INSERT without column list into table with explicit versioning columns produces bad data -create or replace table t1 ( -i int, -s timestamp(6) as row start, -e timestamp(6) as row end, -c varchar(8), -period for system_time(s, e)) with system versioning; -insert into t1 values (1, null, null, 'foo'); -select i, c, e>TIMESTAMP'2038-01-01 00:00:00' AS current_row from t1; -i c current_row -1 foo 1 +create or replace table t2 like t1; +insert into t1(x, y) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000), (6, 6000), (7, 7000), (8, 8000), (9, 9000); +delete from t1 where x >= 1; +insert into t1(x, y) values (1, 1001), (2, 2001), (3, 3001), (4, 4001), (5, 5001), (6, 6001); +insert into t1(x, y, sys_start) values (7, 7001, DEFAULT); +insert into t1(x, y, sys_end) values (8, 8001, DEFAULT); +insert into t1(x, y, sys_start, sys_end) values (9, 9001, DEFAULT, DEFAULT); +insert into t2 select x, y from t1 for system_time all; +select x, y from t1; +x y +1 1001 +2 2001 +3 3001 +4 4001 +5 5001 +6 6001 +7 7001 +8 8001 +9 9001 +select x, y from t2; +x y +1 1000 +2 2000 +3 3000 +4 4000 +5 5000 +6 6000 +7 7000 +8 8000 +9 9000 +1 1001 +2 2001 +3 3001 +4 4001 +5 5001 +6 6001 +7 7001 +8 8001 +9 9001 drop table t1; drop table t2; -drop procedure test_01; -drop procedure test_02; -drop procedure test_03; -drop procedure test_04; -drop procedure test_05; -set timestamp=1000000019; -select now() < sysdate(); -now() < sysdate() -1 -create table t1 (a int) with system versioning; -insert t1 values (1); -set @a=sysdate(6); -select * from t1 for system_time as of now(6); -a -select * from t1 for system_time as of sysdate(6); -a -1 -update t1 set a=2; -delete from t1; -select *, row_start > @a, row_end > @a from t1 for system_time all; -a row_start > @a row_end > @a -1 0 1 -2 1 1 -# -# MDEV-14871 Server crashes in fill_record / fill_record_n_invoke_before_triggers upon inserting into versioned table with trigger -# -create or replace table t1 (pk int primary key) with system versioning; -create trigger tr before insert on t1 for each row select 1 into @a; -insert into t1 values (1),(2); -drop table t1; -create table t1 (pk int primary key, i int) with system versioning; -replace into t1 values (1,10),(1,100),(1,1000); -select pk,i,row_end > '2038-01-01' from t1 for system_time all; -pk i row_end > '2038-01-01' -1 1000 1 -drop table t1; diff --git a/mysql-test/suite/versioning/r/insert2.result b/mysql-test/suite/versioning/r/insert2.result new file mode 100644 index 00000000000..1a8131130b1 --- /dev/null +++ b/mysql-test/suite/versioning/r/insert2.result @@ -0,0 +1,104 @@ +create table t1( +x int unsigned, +sys_start bigint unsigned as row start invisible, +sys_end bigint unsigned as row end invisible, +period for system_time (sys_start, sys_end)) +with system versioning engine=innodb; +create table t2(x int unsigned) engine=innodb; +start transaction; +insert into t1(x) values(1); +commit; +start transaction; +insert into t2(x) values(1); +savepoint a; +insert into t1(x) values(1); +rollback to a; +commit; +insert into t2(x) values (1); +create or replace table t1 ( +x int, +y int as (x) virtual, +sys_trx_start bigint unsigned as row start invisible, +sys_trx_end bigint unsigned as row end invisible, +period for system_time (sys_trx_start, sys_trx_end) +) engine=innodb with system versioning; +insert into t1 values (1, null); +update t1 set x= x + 1; +select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_time all; +x y current +2 2 1 +1 1 0 +create or replace table t1 ( +x int, +row_start timestamp(6) as row start invisible, +row_end timestamp(6) as row end invisible, +period for system_time (row_start, row_end) +) with system versioning; +insert into t1 values (1), (2); +insert into t1 (row_start) select row_end from t1; +ERROR HY000: The value specified for generated column 'row_start' in table 't1' ignored +set sql_mode=''; +insert into t1 (row_start, row_end) values (DEFAULT, 1); +Warnings: +Warning 1906 The value specified for generated column 'row_end' in table 't1' ignored +set sql_mode=default; +select @@sql_mode into @saved_mode; +set sql_mode= ''; +insert into t1 (x, row_start, row_end) values (3, 4, 5); +Warnings: +Warning 1906 The value specified for generated column 'row_start' in table 't1' ignored +Warning 1906 The value specified for generated column 'row_end' in table 't1' ignored +set sql_mode= @saved_mode; +insert into t1 (row_start, row_end) values (DEFAULT, DEFAULT); +select * from t1; +x +1 +2 +NULL +3 +NULL +# MDEV-14792 INSERT without column list into table with explicit versioning columns produces bad data +create or replace table t1 ( +i int, +s timestamp(6) as row start, +e timestamp(6) as row end, +c varchar(8), +period for system_time(s, e)) +with system versioning; +insert into t1 values (1, null, null, 'foo'); +select i, c, e>TIMESTAMP'2038-01-01 00:00:00' AS current_row from t1; +i c current_row +1 foo 1 +drop table t1; +drop table t2; +set timestamp=1000000019; +select now() < sysdate(); +now() < sysdate() +1 +create table t1 (a int) with system versioning; +insert t1 values (1); +set @a=sysdate(6); +select * from t1 for system_time as of now(6); +a +select * from t1 for system_time as of sysdate(6); +a +1 +update t1 set a=2; +delete from t1; +select *, row_start > @a, row_end > @a from t1 for system_time all; +a row_start > @a row_end > @a +1 0 1 +2 1 1 +# +# MDEV-14871 Server crashes in fill_record / fill_record_n_invoke_before_triggers upon inserting into versioned table with trigger +# +create or replace table t1 (pk int primary key) with system versioning; +create trigger tr before insert on t1 for each row select 1 into @a; +insert into t1 values (1),(2); +drop table t1; +create table t1 (pk int primary key, i int) with system versioning; +replace into t1 values (1,10),(1,100),(1,1000); +select pk,i,row_end > '2038-01-01' from t1 for system_time all; +pk i row_end > '2038-01-01' +1 1000 1 +drop table t1; diff --git a/mysql-test/suite/versioning/r/select2,myisam.rdiff b/mysql-test/suite/versioning/r/select2,myisam.rdiff deleted file mode 100644 index b24682fbb9f..00000000000 --- a/mysql-test/suite/versioning/r/select2,myisam.rdiff +++ /dev/null @@ -1,38 +0,0 @@ ---- suite/versioning/r/select_sp.result -+++ suite/versioning/r/select_sp.result -@@ -22,8 +22,6 @@ - delete from t1 where x > 7; - insert into t1(x, y) values(3, 33); - select sys_start from t1 where x = 3 and y = 33 into @t1; --set @x1= @t1; --select vtq_commit_ts(@x1) into @t1; - select x, y from t1; - x y - 0 100 -@@ -84,7 +82,7 @@ - 8 108 - 9 109 - 3 33 --select x as ASOF2_x, y from t1 for system_time as of @x0; -+select x as ASOF2_x, y from t1 for system_time as of @t0; - ASOF2_x y - 0 100 - 1 101 -@@ -96,7 +94,7 @@ - 7 107 - 8 108 - 9 109 --select x as FROMTO2_x, y from t1 for system_time from @x0 to @x1; -+select x as FROMTO2_x, y from t1 for system_time from '0-0-0 0:0:0' to @t1; - FROMTO2_x y - 0 100 - 1 101 -@@ -108,7 +106,7 @@ - 7 107 - 8 108 - 9 109 --select x as BETWAND2_x, y from t1 for system_time between transaction @x0 and transaction @x1; -+select x as BETWAND2_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1; - BETWAND2_x y - 0 100 - 1 101 diff --git a/mysql-test/suite/versioning/r/select2,trx_id.rdiff b/mysql-test/suite/versioning/r/select2,trx_id.rdiff new file mode 100644 index 00000000000..6b1d6527a21 --- /dev/null +++ b/mysql-test/suite/versioning/r/select2,trx_id.rdiff @@ -0,0 +1,38 @@ +--- select2.result ++++ select2,trx_id.result~ +@@ -22,6 +22,8 @@ + delete from t1 where x > 7; + insert into t1(x, y) values(3, 33); + select sys_start from t1 where x = 3 and y = 33 into @t1; ++set @x1= @t1; ++select vtq_commit_ts(@x1) into @t1; + select x, y from t1; + x y + 0 100 +@@ -82,7 +84,7 @@ + 8 108 + 9 109 + 3 33 +-select x as ASOF2_x, y from t1 for system_time as of @t0; ++select x as ASOF2_x, y from t1 for system_time as of @x0; + ASOF2_x y + 0 100 + 1 101 +@@ -94,7 +96,7 @@ + 7 107 + 8 108 + 9 109 +-select x as FROMTO2_x, y from t1 for system_time from '0-0-0 0:0:0' to @t1; ++select x as FROMTO2_x, y from t1 for system_time from @x0 to @x1; + FROMTO2_x y + 0 100 + 1 101 +@@ -106,7 +108,7 @@ + 7 107 + 8 108 + 9 109 +-select x as BETWAND2_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1; ++select x as BETWAND2_x, y from t1 for system_time between transaction @x0 and transaction @x1; + BETWAND2_x y + 0 100 + 1 101 diff --git a/mysql-test/suite/versioning/r/select2.result b/mysql-test/suite/versioning/r/select2.result index 4ec07b1b69e..9267ab8c913 100644 --- a/mysql-test/suite/versioning/r/select2.result +++ b/mysql-test/suite/versioning/r/select2.result @@ -22,8 +22,6 @@ delete from t1 where x = 3; delete from t1 where x > 7; insert into t1(x, y) values(3, 33); select sys_start from t1 where x = 3 and y = 33 into @t1; -set @x1= @t1; -select vtq_commit_ts(@x1) into @t1; select x, y from t1; x y 0 100 @@ -84,7 +82,7 @@ ALL_x y 8 108 9 109 3 33 -select x as ASOF2_x, y from t1 for system_time as of @x0; +select x as ASOF2_x, y from t1 for system_time as of @t0; ASOF2_x y 0 100 1 101 @@ -96,7 +94,7 @@ ASOF2_x y 7 107 8 108 9 109 -select x as FROMTO2_x, y from t1 for system_time from @x0 to @x1; +select x as FROMTO2_x, y from t1 for system_time from '0-0-0 0:0:0' to @t1; FROMTO2_x y 0 100 1 101 @@ -108,7 +106,7 @@ FROMTO2_x y 7 107 8 108 9 109 -select x as BETWAND2_x, y from t1 for system_time between transaction @x0 and transaction @x1; +select x as BETWAND2_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1; BETWAND2_x y 0 100 1 101 diff --git a/mysql-test/suite/versioning/r/update,trx_id.rdiff b/mysql-test/suite/versioning/r/update,trx_id.rdiff new file mode 100644 index 00000000000..037ec548072 --- /dev/null +++ b/mysql-test/suite/versioning/r/update,trx_id.rdiff @@ -0,0 +1,13 @@ +--- suite/versioning/r/update.result ++++ suite/versioning/r/update.reject +@@ -88,10 +88,8 @@ + 5 3 1 + 3 1 0 + 2 1 0 +-3 2 0 + 4 1 0 + 5 1 0 +-5 2 0 + drop table t1; + create table t1 ( + id int primary key auto_increment, diff --git a/mysql-test/suite/versioning/r/update.result b/mysql-test/suite/versioning/r/update.result index 7dd3d6d2124..8e42e7d413d 100644 --- a/mysql-test/suite/versioning/r/update.result +++ b/mysql-test/suite/versioning/r/update.result @@ -1,345 +1,85 @@ -create procedure test_01( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat(' - create table t1( - x int unsigned, - y int unsigned, - sys_trx_start ', sys_type, ' as row start invisible, - sys_trx_end ', sys_type, ' as row end invisible, - period for system_time (sys_trx_start, sys_trx_end)) - with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; -insert into t1(x, y) values -(1, 1000), -(2, 2000), -(3, 3000), -(4, 4000), -(5, 5000), -(6, 6000), -(7, 7000), -(8, 8000), -(9, 9000); +create table t1( +x int unsigned, +y int unsigned, +sys_trx_start SYS_DATATYPE as row start invisible, +sys_trx_end SYS_DATATYPE as row end invisible, +period for system_time (sys_trx_start, sys_trx_end)) +with system versioning; +insert into t1(x, y) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000), (6, 6000), (7, 7000), (8, 8000), (9, 9000); select x, y from t1; +x y +1 1000 +2 2000 +3 3000 +4 4000 +5 5000 +6 6000 +7 7000 +8 8000 +9 9000 update t1 set y = y + 1 where x > 7; select x, y from t1; -select x, y from t1 for system_time -between timestamp '0000-0-0 0:0:0' - and timestamp '2038-01-19 04:14:07'; +x y +1 1000 +2 2000 +3 3000 +4 4000 +5 5000 +6 6000 +7 7000 +8 8001 +9 9001 +select x, y from t1 for system_time all; +x y +1 1000 +2 2000 +3 3000 +4 4000 +5 5000 +6 6000 +7 7000 +8 8001 +9 9001 +8 8000 +9 9000 drop table t1; -end~~ -create procedure test_02( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat(' - create table t1 ( - id bigint primary key, - x int, - y int without system versioning, - sys_trx_start ', sys_type, ' as row start invisible, - sys_trx_end ', sys_type, ' as row end invisible, - period for system_time (sys_trx_start, sys_trx_end)) - with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; +create table t1 ( +id bigint primary key, +x int, +y int without system versioning, +sys_trx_start SYS_DATATYPE as row start invisible, +sys_trx_end SYS_DATATYPE as row end invisible, +period for system_time (sys_trx_start, sys_trx_end)) +with system versioning; insert into t1 values(1, 1, 1); set @ins_t= now(6); select sys_trx_start into @tmp1 from t1; update t1 set x= 11, y= 11 where id = 1; select @tmp1 < sys_trx_start as A1, x, y from t1; +A1 x y +1 11 11 select sys_trx_start into @tmp1 from t1; update t1 set y= 1 where id = 1; select @tmp1 = sys_trx_start as A2, x from t1; +A2 x +1 11 drop table t1; -end~~ -create procedure test_03( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat(' - create table t1 ( - x int, - y int, - sys_trx_start bigint unsigned as row start invisible, - sys_trx_end bigint unsigned as row end invisible, - period for system_time (sys_trx_start, sys_trx_end) - ) with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; +create table t1 ( +x int, +y int, +sys_trx_start SYS_DATATYPE as row start invisible, +sys_trx_end SYS_DATATYPE as row end invisible, +period for system_time (sys_trx_start, sys_trx_end) +) with system versioning; insert into t1 (x, y) values (1, 1), (2, 1), (3, 1), (4, 1), (5, 1); -start transaction; +start transaction; update t1 set y= y + 1 where x = 3; update t1 set y= y + 1 where x = 2; update t1 set y= y + 1 where x = 3; update t1 set y= y + 1 where x > 3; update t1 set y= y + 1 where x > 4; commit; -select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_time all; -drop table t1; -end~~ -create procedure test_04( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat(' - create table t1 ( - id int primary key auto_increment, - x int, - sys_trx_start ', sys_type, ' as row start invisible, - sys_trx_end ', sys_type, ' as row end invisible, - period for system_time (sys_trx_start, sys_trx_end)) - with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; -set @t0= now(6); -insert into t1 (x) values (1); -set @t1= now(6); -update t1 set x= 2 where id = 1; -set @t2= now(6); -update t1 set x= 3 where id = 1; -select x from t1 for system_time as of timestamp @t0; -select x from t1 for system_time as of timestamp @t1; -select x from t1 for system_time as of timestamp @t2; -select x from t1 for system_time as of timestamp now(6); -drop table t1; -end~~ -create procedure test_05( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat(' - create table t1( - x int unsigned, - sys_trx_end ', sys_type, ' as row end invisible, - sys_trx_start ', sys_type, ' as row start invisible, - y int unsigned, - period for system_time (sys_trx_start, sys_trx_end), - primary key(x, y)) - with system versioning - engine ', engine); -prepare stmt from @str; execute stmt; drop prepare stmt; -insert into t1(x, y) values -(1, 1000), -(3, 3000), -(4, 4000), -(5, 5000); -insert into t1(x, y) values(3, 3000) on duplicate key update y = y+1; -insert into t1(x, y) values(4, 4444) on duplicate key update y = y+1; -select x, y from t1 for system_time all; -select x, y from t1; -drop table t1; -end~~ -create procedure test_06( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat('( - x int unsigned, - y int unsigned, - sys_trx_start ', sys_type, ' as row start invisible, - sys_trx_end ', sys_type, ' as row end invisible, - period for system_time (sys_trx_start, sys_trx_end)) - with system versioning - engine ', engine); -set @str2= concat('create table t1', @str); -prepare stmt from @str2; execute stmt; drop prepare stmt; -set @str2= concat('create table t2', @str); -prepare stmt from @str2; execute stmt; drop prepare stmt; -insert into t1(x, y) values -(1, 1000), -(2, 2000), -(3, 3000), -(4, 4000), -(5, 5000), -(6, 6000), -(7, 7000), -(8, 8000), -(9, 9000); -insert into t2(x, y) values -(1, 1010), -(2, 2010), -(3, 3010), -(4, 4010), -(5, 5010), -(6, 6010), -(7, 7010), -(8, 8010), -(9, 9010); -update t1, t2 set t1.y = t1.x + t1.y, t2.y = t2.x + t2.y where t1.x > 7 and t2.x < 7; -select x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp '9999-1-1 0:0:0'; -select x, y from t1; -select x, y from t2 for system_time between timestamp '0-0-0 0:0:0' and timestamp '9999-1-1 0:0:0'; -select x, y from t2; -drop table t1; -drop table t2; -end~~ -create procedure test_07( -sys_type varchar(255), -engine varchar(255), -fields varchar(255)) -begin -set @str= concat('( - id bigint primary key without system versioning, - name varchar(128), - salary bigint without system versioning, - sys_trx_start ', sys_type, ' as row start invisible, - sys_trx_end ', sys_type, ' as row end invisible, - period for system_time (sys_trx_start, sys_trx_end)) - with system versioning - engine ', engine); -set @str2= concat('create table t1', @str); -prepare stmt from @str2; execute stmt; drop prepare stmt; -set @str2= concat('create table t2', @str); -prepare stmt from @str2; execute stmt; drop prepare stmt; -insert into t1 values (1, "Jeremy", 3000); -insert into t2 values (1, "Jeremy", 4000); -select sys_trx_start into @tmp1 from t1; -select sys_trx_start into @tmp2 from t2; -update t1, t2 set t1.name= "Jerry", t2.name= "Jerry" where t1.id = t2.id and t1.name = "Jeremy"; -select @tmp1 < sys_trx_start as A1, name from t1; -select @tmp2 < sys_trx_start as A2, name from t2; -select sys_trx_start into @tmp1 from t1; -select sys_trx_start into @tmp2 from t2; -update t1, t2 set t1.salary= 2500, t2.salary= 2500 where t1.id = t2.id and t1.name = "Jerry"; -select @tmp1 = sys_trx_start as B1, salary from t1; -select @tmp2 = sys_trx_start as B2, salary from t2; -drop table t1; -drop table t2; -end~~ -call test_01('timestamp(6)', 'myisam', 'sys_trx_end'); -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8000 -9 9000 -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8001 -9 9001 -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8001 -9 9001 -8 8000 -9 9000 -call test_01('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8000 -9 9000 -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8001 -9 9001 -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8001 -9 9001 -8 8000 -9 9000 -call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8000 -9 9000 -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8001 -9 9001 -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8001 -9 9001 -8 8000 -9 9000 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 -call test_02('timestamp(6)', 'myisam', 'sys_trx_end'); -A1 x y -1 11 11 -A2 x -1 11 -call test_02('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -A1 x y -1 11 11 -A2 x -1 11 -call test_02('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -A1 x y -1 11 11 -A2 x -1 11 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 -# Multiple UPDATE of same rows in single transaction create historical -# rows only once (applicable to transaction-based only). -call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); +select x, y, sys_trx_end = MAXVAL as current from t1 for system_time all; x y current 1 1 1 2 2 1 @@ -348,42 +88,48 @@ x y current 5 3 1 3 1 0 2 1 0 +3 2 0 4 1 0 5 1 0 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 -call test_04('timestamp(6)', 'myisam', 'sys_trx_end'); +5 2 0 +drop table t1; +create table t1 ( +id int primary key auto_increment, +x int, +sys_trx_start SYS_DATATYPE as row start invisible, +sys_trx_end SYS_DATATYPE as row end invisible, +period for system_time (sys_trx_start, sys_trx_end)) +with system versioning; +set @t0= now(6); +insert into t1 (x) values (1); +set @t1= now(6); +update t1 set x= 2 where id = 1; +set @t2= now(6); +update t1 set x= 3 where id = 1; +select x from t1 for system_time as of timestamp @t0; x +select x from t1 for system_time as of timestamp @t1; x 1 +select x from t1 for system_time as of timestamp @t2; x 2 +select x from t1 for system_time as of timestamp now(6); x 3 -call test_04('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -x -x -1 -x -2 -x -3 -call test_04('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -x -x -1 -x -2 -x -3 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 -3 1 1 1 1 -call test_05('timestamp(6)', 'myisam', 'sys_trx_end'); +drop table t1; +create table t1( +x int unsigned, +sys_trx_end SYS_DATATYPE as row end invisible, +sys_trx_start SYS_DATATYPE as row start invisible, +y int unsigned, +period for system_time (sys_trx_start, sys_trx_end), +primary key(x, y)) +with system versioning; +insert into t1(x, y) values (1, 1000), (3, 3000), (4, 4000), (5, 5000); +insert into t1(x, y) values(3, 3000) on duplicate key update y = y+1; +insert into t1(x, y) values(4, 4444) on duplicate key update y = y+1; +select x, y from t1 for system_time all; x y 1 1000 3 3000 @@ -391,46 +137,26 @@ x y 4 4000 4 4444 5 5000 +select x, y from t1; x y 1 1000 3 3001 4 4000 4 4444 5 5000 -call test_05('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -x y -1 1000 -3 3000 -3 3001 -4 4000 -4 4444 -5 5000 -x y -1 1000 -3 3001 -4 4000 -4 4444 -5 5000 -call test_05('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -x y -1 1000 -3 3000 -3 3001 -4 4000 -4 4444 -5 5000 -x y -1 1000 -3 3001 -4 4000 -4 4444 -5 5000 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 -3 1 1 1 1 -call test_06('timestamp(6)', 'myisam', 'sys_trx_end'); +drop table t1; +create table t1 ( +x int unsigned, +y int unsigned, +sys_trx_start SYS_DATATYPE as row start invisible, +sys_trx_end SYS_DATATYPE as row end invisible, +period for system_time (sys_trx_start, sys_trx_end)) +with system versioning; +create table t2 like t1; +insert into t1(x, y) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000), (6, 6000), (7, 7000), (8, 8000), (9, 9000); +insert into t2(x, y) values (1, 1010), (2, 2010), (3, 3010), (4, 4010), (5, 5010), (6, 6010), (7, 7010), (8, 8010), (9, 9010); +update t1, t2 set t1.y = t1.x + t1.y, t2.y = t2.x + t2.y where t1.x > 7 and t2.x < 7; +select x, y from t1 for system_time all; x y 1 1000 2 2000 @@ -443,6 +169,7 @@ x y 9 9009 8 8000 9 9000 +select x, y from t1; x y 1 1000 2 2000 @@ -453,6 +180,7 @@ x y 7 7000 8 8008 9 9009 +select x, y from t2 for system_time all; x y 1 1011 2 2012 @@ -469,6 +197,7 @@ x y 4 4010 5 5010 6 6010 +select x, y from t2; x y 1 1011 2 2012 @@ -479,161 +208,36 @@ x y 7 7010 8 8010 9 9010 -call test_06('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8008 -9 9009 -8 8000 -9 9000 -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8008 -9 9009 -x y -1 1011 -2 2012 -3 3013 -4 4014 -5 5015 -6 6016 -7 7010 -8 8010 -9 9010 -1 1010 -2 2010 -3 3010 -4 4010 -5 5010 -6 6010 -x y -1 1011 -2 2012 -3 3013 -4 4014 -5 5015 -6 6016 -7 7010 -8 8010 -9 9010 -call test_06('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8008 -9 9009 -8 8000 -9 9000 -x y -1 1000 -2 2000 -3 3000 -4 4000 -5 5000 -6 6000 -7 7000 -8 8008 -9 9009 -x y -1 1011 -2 2012 -3 3013 -4 4014 -5 5015 -6 6016 -7 7010 -8 8010 -9 9010 -1 1010 -2 2010 -3 3010 -4 4010 -5 5010 -6 6010 -x y -1 1011 -2 2012 -3 3013 -4 4014 -5 5015 -6 6016 -7 7010 -8 8010 -9 9010 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 -3 1 1 1 1 -# Optimized fields -call test_07('timestamp(6)', 'myisam', 'sys_trx_end'); +drop table t1; +drop table t2; +create table t1 ( +id bigint primary key without system versioning, +name varchar(128), +salary bigint without system versioning, +sys_trx_start SYS_DATATYPE as row start invisible, +sys_trx_end SYS_DATATYPE as row end invisible, +period for system_time (sys_trx_start, sys_trx_end)) +with system versioning; +create table t2 like t1; +insert into t1 values (1, "Jeremy", 3000); +insert into t2 values (1, "Jeremy", 4000); +select sys_trx_start into @tmp1 from t1; +select sys_trx_start into @tmp2 from t2; +update t1, t2 set t1.name= "Jerry", t2.name= "Jerry" where t1.id = t2.id and t1.name = "Jeremy"; +select @tmp1 < sys_trx_start as A1, name from t1; A1 name 1 Jerry +select @tmp2 < sys_trx_start as A2, name from t2; A2 name 1 Jerry +select sys_trx_start into @tmp1 from t1; +select sys_trx_start into @tmp2 from t2; +update t1, t2 set t1.salary= 2500, t2.salary= 2500 where t1.id = t2.id and t1.name = "Jerry"; +select @tmp1 = sys_trx_start as B1, salary from t1; B1 salary 1 2500 +select @tmp2 = sys_trx_start as B2, salary from t2; B2 salary 1 2500 -call test_07('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -A1 name -1 Jerry -A2 name -1 Jerry -B1 salary -1 2500 -B2 salary -1 2500 -call test_07('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -A1 name -1 Jerry -A2 name -1 Jerry -B1 salary -1 2500 -B2 salary -1 2500 -call verify_vtq; -No A B C D -1 1 1 1 1 -2 1 1 1 1 -3 1 1 1 1 -### Issue #365, bug 7 (duplicate of historical row) -create or replace table t1 (a int primary key, b int) -with system versioning engine myisam; -insert into t1 (a) values (1); -replace t1 values (1,2),(1,3),(2,4); -create or replace table t1 (pk int, a char(3), b char(3), primary key(pk)) -engine=innodb with system versioning; -insert into t1 (pk) values (1); -connect con1,localhost,root,,test; -start transaction; -select * from t1 for update; -pk a b -1 NULL NULL -connection default; -update t1 set b = 'foo'; -connection con1; -update t1 set a = 'bar'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction -disconnect con1; -connection default; -drop database test; -create database test; +drop table t1; +drop table t2; diff --git a/mysql-test/suite/versioning/r/update2.result b/mysql-test/suite/versioning/r/update2.result new file mode 100644 index 00000000000..73e6c5b393d --- /dev/null +++ b/mysql-test/suite/versioning/r/update2.result @@ -0,0 +1,21 @@ +### Issue #365, bug 7 (duplicate of historical row) +create or replace table t1 (a int primary key, b int) +with system versioning engine myisam; +insert into t1 (a) values (1); +replace t1 values (1,2),(1,3),(2,4); +create or replace table t1 (pk int, a char(3), b char(3), primary key(pk)) +engine=innodb with system versioning; +insert into t1 (pk) values (1); +connect con1,localhost,root,,test; +start transaction; +select * from t1 for update; +pk a b +1 NULL NULL +connection default; +update t1 set b = 'foo'; +connection con1; +update t1 set a = 'bar'; +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +disconnect con1; +connection default; +drop table t1; diff --git a/mysql-test/suite/versioning/t/auto_increment.test b/mysql-test/suite/versioning/t/auto_increment.test index 6108f6d9818..804c0424179 100644 --- a/mysql-test/suite/versioning/t/auto_increment.test +++ b/mysql-test/suite/versioning/t/auto_increment.test @@ -1,68 +1,50 @@ +-- source suite/versioning/engines.inc -- source suite/versioning/common.inc -delimiter ~~; -create procedure test_01( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat(' - create table t1( +--replace_result $sys_datatype_expl SYS_DATATYPE +eval create table t1( id int unsigned auto_increment primary key, x int unsigned, y int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, + sys_start $sys_datatype_expl as row start invisible, + sys_end $sys_datatype_expl as row end invisible, period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; + with system versioning; - set @str= concat(' - create table t2( +eval create table t2( id int unsigned auto_increment primary key, x int unsigned, - y int unsigned) - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; + y int unsigned); - insert into t1(x, y) values(1, 11); - insert into t2(x, y) values(1, 11); - insert into t1(x, y) values(2, 12); - insert into t2(x, y) values(2, 12); - insert into t1(x, y) values(3, 13); - insert into t2(x, y) values(3, 13); - insert into t1(x, y) values(4, 14); - insert into t2(x, y) values(4, 14); - insert into t1(x, y) values(5, 15); - insert into t2(x, y) values(5, 15); - insert into t1(x, y) values(6, 16); - insert into t2(x, y) values(6, 16); - insert into t1(x, y) values(7, 17); - insert into t2(x, y) values(7, 17); - insert into t1(x, y) values(8, 18); - insert into t2(x, y) values(8, 18); - insert into t1(x, y) values(9, 19); - insert into t2(x, y) values(9, 19); +insert into t1(x, y) values(1, 11); +insert into t2(x, y) values(1, 11); +insert into t1(x, y) values(2, 12); +insert into t2(x, y) values(2, 12); +insert into t1(x, y) values(3, 13); +insert into t2(x, y) values(3, 13); +insert into t1(x, y) values(4, 14); +insert into t2(x, y) values(4, 14); +insert into t1(x, y) values(5, 15); +insert into t2(x, y) values(5, 15); +insert into t1(x, y) values(6, 16); +insert into t2(x, y) values(6, 16); +insert into t1(x, y) values(7, 17); +insert into t2(x, y) values(7, 17); +insert into t1(x, y) values(8, 18); +insert into t2(x, y) values(8, 18); +insert into t1(x, y) values(9, 19); +insert into t2(x, y) values(9, 19); - select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner join t2 on t1.id = t2.id; - delete from t1 where x = 2; - delete from t2 where x = 2; - - select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner join t2 on t1.id = t2.id; - delete from t1 where x > 7; - delete from t2 where x > 7; - - select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner join t2 on t1.id = t2.id; - drop table t1; - drop table t2; -end~~ -delimiter ;~~ +select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner join t2 on t1.id = t2.id; +delete from t1 where x = 2; +delete from t2 where x = 2; -call test_01('timestamp(6)', 'myisam', 'sys_end'); -call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -call verify_vtq; +select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner join t2 on t1.id = t2.id; +delete from t1 where x > 7; +delete from t2 where x > 7; -drop procedure test_01; +select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner join t2 on t1.id = t2.id; +drop table t1; +drop table t2; -- source suite/versioning/common_finish.inc diff --git a/mysql-test/suite/versioning/t/create.test b/mysql-test/suite/versioning/t/create.test index 24d8d335020..ce135e66ec9 100644 --- a/mysql-test/suite/versioning/t/create.test +++ b/mysql-test/suite/versioning/t/create.test @@ -22,33 +22,33 @@ show create table t1; create or replace table t1 ( x2 int unsigned ) with system versioning; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t1; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE --error ER_VERS_PERIOD_COLUMNS eval create or replace table t1 ( x3 int unsigned, - Sys_start $sys_datatype as row start invisible, - Sys_end $sys_datatype as row end invisible, + Sys_start timestamp(6) as row start invisible, + Sys_end timestamp(6) as row end invisible, period for system_time (x, Sys_end) ) with system versioning; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE --error ER_VERS_PERIOD_COLUMNS eval create or replace table t1 ( x4 int unsigned, - Sys_start $sys_datatype as row start invisible, - Sys_end2 $sys_datatype as row end invisible, + Sys_start timestamp(6) as row start invisible, + Sys_end2 timestamp(6) as row end invisible, period for system_time (Sys_start, Sys_end) ) with system versioning; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE --error ER_VERS_PERIOD_COLUMNS eval create or replace table t1 ( x5 int unsigned, - Sys_start $sys_datatype as row start invisible, - Sys_end $sys_datatype as row end invisible, + Sys_start timestamp(6) as row start invisible, + Sys_end timestamp(6) as row end invisible, period for system_time (Sys_start, x) ) with system versioning; @@ -58,39 +58,39 @@ create or replace table t1 ( period for system_time (Sys_start, Sys_end) ) with system versioning; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE --error ER_MISSING eval create or replace table t1 ( x7 int unsigned, - Sys_start $sys_datatype as row start invisible, - Sys_end $sys_datatype as row end invisible, + Sys_start timestamp(6) as row start invisible, + Sys_end timestamp(6) as row end invisible, period for system_time (Sys_start, Sys_end) ); ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE --error ER_VERS_PERIOD_COLUMNS eval create or replace table t1 ( x8 int unsigned, - Sys_start $sys_datatype as row start invisible, - Sys_end $sys_datatype as row end invisible, + Sys_start timestamp(6) as row start invisible, + Sys_end timestamp(6) as row end invisible, period for system_time (sys_insert, sys_remove) ) with system versioning; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE --error ER_MISSING eval create or replace table t1 ( x9 int unsigned, - Sys_start $sys_datatype as row start invisible, - Sys_end $sys_datatype as row end invisible, + Sys_start timestamp(6) as row start invisible, + Sys_end timestamp(6) as row end invisible, period for system_time (Sys_start, Sys_end) ); ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE --error ER_MISSING eval create or replace table t1 ( x10 int unsigned, - Sys_start $sys_datatype as row start invisible, - Sys_end $sys_datatype as row end invisible, + Sys_start timestamp(6) as row start invisible, + Sys_end timestamp(6) as row end invisible, period for system_time (Sys_start, Sys_start) ); @@ -132,14 +132,14 @@ create or replace table t1 ( x15 int with system versioning, B int ); ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t1; create or replace table t1 ( x16 int with system versioning, B int ) with system versioning; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t1; create or replace table t1 ( @@ -151,21 +151,21 @@ create or replace table t1 ( x18 int, B int without system versioning ) with system versioning; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t1; create or replace table t1 ( x19 int with system versioning, B int without system versioning ); ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t1; create or replace table t1 ( x20 int with system versioning, B int without system versioning ) with system versioning; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t1; create or replace table t1 ( @@ -180,34 +180,34 @@ create or replace table t1 ( # CREATE TABLE ... LIKE create or replace table t1 (a int) with system versioning; create table tt1 like t1; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table tt1; drop table tt1; create temporary table tt1 like t1; --echo # Temporary is stripped from versioning ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table tt1; --echo # CREATE TABLE ... SELECT create or replace table t1 (x23 int) with system versioning; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE eval create or replace table t0( y int, - st $sys_datatype as row start, - en $sys_datatype as row end, + st timestamp(6) as row start, + en timestamp(6) as row end, period for system_time (st, en) ) with system versioning; --echo ## For non-versioned table: --echo ### 1. invisible fields are not included create or replace table t2 as select * from t1; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t2; --echo ### 2. all visible fields are included create or replace table t3 as select * from t0; select * from t0; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t3; --echo ## For versioned table @@ -217,7 +217,7 @@ insert into t0 (y) values (2); select st from t0 into @st; create or replace table t2 with system versioning as select * from t1; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t2; --echo #### invisible fields are not copied select * from t2; @@ -225,26 +225,26 @@ select * from t2 where row_start <= @row_start; --echo ### 2. source table with visible system fields, target with invisible create or replace table t3 with system versioning as select * from t0; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t3; select * from t3 where y > 2; select y from t3 where st = @st and row_start > @st; --echo ### 3. source and target table with visible system fields ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE eval create or replace table t3 ( - st $sys_datatype as row start invisible, - en $sys_datatype as row end invisible, + st timestamp(6) as row start invisible, + en timestamp(6) as row end invisible, period for system_time (st, en) ) with system versioning as select * from t0; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t3; select y from t3; select y from t3 where st = @st; --echo ### 4. system fields not or wrongly selected create or replace table t3 with system versioning select x23 from t1; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t3; select * from t3; --error ER_MISSING @@ -262,7 +262,7 @@ select en from t0 for system_time all into @en; create or replace table t2 (y int); insert into t2 values (3); create or replace table t3 with system versioning select * from t1 for system_time all, t2; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t3; select * from t3 for system_time all; select * from t3 for system_time all where row_start = @row_start and row_end = @row_end; @@ -278,16 +278,16 @@ select st, en from t3 where y = 2 into @st, @en; select y from t2 for system_time all where st = @st and en = @en; --echo ## Default engine detection ---replace_result $non_default_engine NON_DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $non_default_engine NON_DEFAULT_ENGINE eval create or replace table t1 (x25 int) with system versioning engine $non_default_engine; create or replace table t2 as select x25, row_start, row_end from t1 for system_time all; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t2; create or replace table t2 with system versioning as select x25, row_start, row_end from t1; ---replace_result $non_default_engine NON_DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $non_default_engine NON_DEFAULT_ENGINE show create table t2; create or replace table t1 ( @@ -305,7 +305,7 @@ eval create or replace table t1 (x27 int, id int) with system versioning engine create or replace table t2 (b int, id int); create or replace table t3 with system versioning as select t2.b, t1.x27, t1.row_start, t1.row_end from t2 inner join t1 on t2.id=t1.id; ---replace_result $non_default_engine NON_DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE +--replace_result $non_default_engine NON_DEFAULT_ENGINE show create table t3; --echo ## Errors @@ -333,28 +333,28 @@ create or replace table t1 ( --echo ## System fields detection create or replace table t1 (x30 int) with system versioning; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE eval create or replace table t2 ( y int, - st $sys_datatype as row start invisible, - en $sys_datatype as row end invisible, + st timestamp(6) as row start invisible, + en timestamp(6) as row end invisible, period for system_time (st, en) ) with system versioning; create or replace table t3 as select x30, y, row_start, row_end, st, en from t1, t2; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t3; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE eval create or replace table t3 ( y int, - st $sys_datatype as row start invisible, - en $sys_datatype as row end invisible, + st timestamp(6) as row start invisible, + en timestamp(6) as row end invisible, period for system_time (st, en) ) with system versioning as select x30, y, row_start, row_end, st, en from t1, t2; ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t3; --echo # MDEV-14828 Server crashes in JOIN::prepare / setup_fields on 2nd execution of PS [#437] diff --git a/mysql-test/suite/versioning/t/delete.test b/mysql-test/suite/versioning/t/delete.test index dc228b0db72..4c2f4daccd7 100644 --- a/mysql-test/suite/versioning/t/delete.test +++ b/mysql-test/suite/versioning/t/delete.test @@ -1,122 +1,79 @@ --- source suite/versioning/common.inc +source suite/versioning/engines.inc; +source suite/versioning/common.inc; -delimiter ~~; -create or replace procedure test_01( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat(' - create or replace table t1( +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create or replace table t1( XNo int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, + sys_start $sys_datatype_expl as row start invisible, + sys_end $sys_datatype_expl as row end invisible, period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; - insert into t1(XNo) values(0); - insert into t1(XNo) values(1); - insert into t1(XNo) values(2); - insert into t1(XNo) values(3); - insert into t1(XNo) values(4); - insert into t1(XNo) values(5); - insert into t1(XNo) values(6); - insert into t1(XNo) values(7); - insert into t1(XNo) values(8); - insert into t1(XNo) values(9); - set @str= concat('select XNo, ', - fields, " < '2038-01-19 03:14:07' - from t1 for system_time - between timestamp '0000-0-0 0:0:0' - and timestamp '2038-01-19 04:14:07'"); - prepare stmt from @str; execute stmt; - delete from t1 where XNo = 0; - select "Deleted 0"; - execute stmt; - delete from t1 where XNo = 1; - select "Deleted 1"; - execute stmt; - delete from t1 where XNo > 5; - select "Deleted >5"; - create view vt1 as select XNo from t1; - select XNo as XNo_vt1 from vt1; - delete from vt1 where XNo = 3; - select "Deleted from VIEW 3"; - select XNo as XNo_vt1 from vt1; - execute stmt; drop prepare stmt; - drop view vt1; - drop table t1; -end~~ + with system versioning; -create or replace procedure test_02( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat('create or replace table t1 ( +insert into t1(XNo) values(0); +insert into t1(XNo) values(1); +insert into t1(XNo) values(2); +insert into t1(XNo) values(3); +insert into t1(XNo) values(4); +insert into t1(XNo) values(5); +insert into t1(XNo) values(6); +insert into t1(XNo) values(7); +insert into t1(XNo) values(8); +insert into t1(XNo) values(9); +replace_result $sys_datatype_max MAXVAL; +eval select XNo, sys_end < $sys_datatype_max from t1 for system_time all; +delete from t1 where XNo = 0; +delete from t1 where XNo = 1; +delete from t1 where XNo > 5; +create view vt1 as select XNo from t1; +select XNo as XNo_vt1 from vt1; +delete from vt1 where XNo = 3; +select XNo as XNo_vt1 from vt1; +drop view vt1; +drop table t1; + + +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create or replace table t1( x int, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, + sys_start $sys_datatype_expl as row start invisible, + sys_end $sys_datatype_expl as row end invisible, period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; - insert into t1(x) values (1); - select sys_start into @sys_start from t1; - delete from t1; - select * from t1; - select x = 1 as A, sys_start = @sys_start as B, sys_end > sys_start as C - from t1 for system_time all; - drop table t1; -end~~ + with system versioning; -create or replace procedure test_03( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str0= concat('( +insert into t1(x) values (1); +select sys_start into @sys_start from t1; +delete from t1; +select * from t1; +select x = 1 as A, sys_start = @sys_start as B, sys_end > sys_start as C from t1 for system_time all; +drop table t1; + +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create or replace table t1( x int, y int, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, + sys_start $sys_datatype_expl as row start invisible, + sys_end $sys_datatype_expl as row end invisible, period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); - set @str= concat('create or replace table t1', @str0); - prepare stmt from @str; execute stmt; drop prepare stmt; - set @str= concat('create or replace table t2', @str0); - prepare stmt from @str; execute stmt; drop prepare stmt; - insert into t1(x, y) values (1, 1), (2, 2), (3, 3), (14, 4); - insert into t2(x, y) values (11, 1), (12, 2), (13, 32), (14, 4); - delete t1, t2 from t1 join t2 where t1.y = 3 and t2.y = 32; - select x as t1_x from t1; - select x as t2_x from t2; - delete t1, t2 from t1 join t2 where t1.x = t2.x; - select x as t1_x from t1; - select x as t2_x from t2; - select x as t1_x_all from t1 for system_time all; - select x as t2_x_all from t2 for system_time all; - drop table t1; - drop table t2; -end~~ -delimiter ;~~ + with system versioning; +create or replace table t2 like t1; +insert into t1(x, y) values (1, 1), (2, 2), (3, 3), (14, 4); +insert into t2(x, y) values (11, 1), (12, 2), (13, 32), (14, 4); +delete t1, t2 from t1 join t2 where t1.y = 3 and t2.y = 32; +select x as t1_x from t1; +select x as t2_x from t2; +delete t1, t2 from t1 join t2 where t1.x = t2.x; +select x as t1_x from t1; +select x as t2_x from t2; +select x as t1_x_all from t1 for system_time all; +select x as t2_x_all from t2 for system_time all; +drop table t1; +drop table t2; --echo # Basic + delete from view -call test_01('timestamp(6)', 'myisam', 'sys_end'); -call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -call verify_vtq; --echo # Check sys_start, sys_end -call test_02('timestamp(6)', 'myisam', 'sys_end'); -call test_02('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -call verify_vtq; --echo # Multi-delete -call test_03('timestamp(6)', 'myisam', 'sys_end'); -call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -call verify_vtq; --echo # Update + delete create or replace table t1 (x int) with system versioning; diff --git a/mysql-test/suite/versioning/t/insert.test b/mysql-test/suite/versioning/t/insert.test index 01d10c1c21f..0324df64d0c 100644 --- a/mysql-test/suite/versioning/t/insert.test +++ b/mysql-test/suite/versioning/t/insert.test @@ -1,278 +1,82 @@ --- source suite/versioning/common.inc +source suite/versioning/engines.inc; +source suite/versioning/common.inc; -delimiter ~~; -create procedure test_01( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat(' - create table t1( - x int unsigned, - y int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; - insert into t1(x, y) values(3, 4); - insert delayed into t1(x, y) values(2, 3); - insert into t1 values(40, 33); - set @str= concat('select x, y, ', fields, ' from t1'); - prepare stmt from @str; execute stmt; drop prepare stmt; - drop table t1; -end~~ - -create procedure test_02( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat(' - create table t1( - id int unsigned auto_increment primary key, - x int unsigned, - y int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; - insert into t1(x, y) values(33, 44); - insert into t1(id, x, y) values(20, 33, 44); - insert into t1 values(40, 33, 44); - set @str= concat('select id, x, y, ', fields, ' from t1'); - prepare stmt from @str; execute stmt; drop prepare stmt; - drop table t1; -end~~ - -create procedure test_03( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat(' - create table t1( - x int unsigned, - y int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; - create view vt1_1 as select x, y from t1; - insert into t1(x, y) values(8001, 9001); - insert into vt1_1(x, y) values(1001, 2001); - insert into vt1_1 values(1002, 2002); - set @str= concat('select x, y, ', fields, ' from t1'); - prepare stmt from @str; execute stmt; drop prepare stmt; - select x, y from vt1_1; -end~~ - -create procedure test_04( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat(' - create table t1( - id bigint primary key, - a int, - b int) - with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; - insert into t1 values(1, 1, 1); - select row_start, row_end from t1 into @sys_start, @sys_end; - select id, a, b from t1; - insert into t1 values(2, 2, 2); - select id, a, b, row_start > @sys_start as C, row_end = @sys_end as D from t1 where id = 2; - drop table t1; -end~~ - -create procedure test_05( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat('( - x int unsigned, - y int unsigned, - sys_start ', sys_type, ' as row start invisible, - sys_end ', sys_type, ' as row end invisible, - period for system_time (sys_start, sys_end)) - with system versioning - engine ', engine); - set @str2= concat('create table t1', @str); - prepare stmt from @str2; execute stmt; drop prepare stmt; - set @str2= concat('create table t2', @str); - prepare stmt from @str2; execute stmt; drop prepare stmt; - insert into t1(x, y) values - (1, 1000), - (2, 2000), - (3, 3000), - (4, 4000), - (5, 5000), - (6, 6000), - (7, 7000), - (8, 8000), - (9, 9000); - delete from t1 where x >= 1; - insert into t1(x, y) values - (1, 1001), - (2, 2001), - (3, 3001), - (4, 4001), - (5, 5001), - (6, 6001); - insert into t1(x, y, sys_start) values - (7, 7001, DEFAULT); - insert into t1(x, y, sys_end) values - (8, 8001, DEFAULT); - insert into t1(x, y, sys_start, sys_end) values - (9, 9001, DEFAULT, DEFAULT); - insert into t2 select x, y from t1 for system_time between timestamp '0000-0-0 0:0:0' and timestamp '9999-1-1 0:0:0'; - select x, y from t1; - select x, y from t2; - drop table t1; - drop table t2; -end~~ -delimiter ;~~ - -call test_01('timestamp(6)', 'myisam', 'sys_end'); -call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); - -call test_02('timestamp(6)', 'myisam', 'sys_end'); -call test_02('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); - -call test_03('timestamp(6)', 'myisam', 'sys_end'); -drop table t1; -drop view vt1_1; - -call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); -drop table t1; -drop view vt1_1; - -call test_04('timestamp(6)', 'myisam', 'sys_end'); -call test_04('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); - -call test_05('timestamp(6)', 'myisam', 'sys_end'); -call test_05('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)'); - -# VTQ test - -call verify_vtq; - -create table t1( +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create or replace table t1( x int unsigned, - sys_start bigint unsigned as row start invisible, - sys_end bigint unsigned as row end invisible, + y int unsigned, + sys_start $sys_datatype_expl as row start invisible, + sys_end $sys_datatype_expl as row end invisible, period for system_time (sys_start, sys_end)) -with system versioning engine=innodb; - -create table t2(x int unsigned) engine=innodb; - -start transaction; -insert into t1(x) values(1); -commit; -call verify_vtq; - -start transaction; -insert into t2(x) values(1); -savepoint a; -insert into t1(x) values(1); -rollback to a; -commit; -call verify_vtq; - -insert into t2(x) values (1); - -# virtual columns -create or replace table t1 ( - x int, - y int as (x) virtual, - sys_trx_start bigint unsigned as row start invisible, - sys_trx_end bigint unsigned as row end invisible, - period for system_time (sys_trx_start, sys_trx_end) -) engine=innodb with system versioning; -insert into t1 values (1, null); -update t1 set x= x + 1; -select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_time all; - -create or replace table t1 ( - x int, - row_start timestamp(6) as row start invisible, - row_end timestamp(6) as row end invisible, - period for system_time (row_start, row_end) -) with system versioning; -insert into t1 values (1), (2); ---error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN -insert into t1 (row_start) select row_end from t1; -set sql_mode=''; -insert into t1 (row_start, row_end) values (DEFAULT, 1); -set sql_mode=default; -select @@sql_mode into @saved_mode; -set sql_mode= ''; -insert into t1 (x, row_start, row_end) values (3, 4, 5); -set sql_mode= @saved_mode; -insert into t1 (row_start, row_end) values (DEFAULT, DEFAULT); -select * from t1; - ---echo # MDEV-14792 INSERT without column list into table with explicit versioning columns produces bad data -create or replace table t1 ( - i int, - s timestamp(6) as row start, - e timestamp(6) as row end, - c varchar(8), - period for system_time(s, e)) with system versioning; -insert into t1 values (1, null, null, 'foo'); -select i, c, e>TIMESTAMP'2038-01-01 00:00:00' AS current_row from t1; +insert into t1(x, y) values(3, 4); +insert into t1(x, y) values(2, 3); +insert into t1 values(40, 33); +replace_result $sys_datatype_max MAXVAL; +eval select x, y, sys_end < $sys_datatype_max from t1; + +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create or replace table t1( + id int unsigned auto_increment primary key, + x int unsigned, + y int unsigned, + sys_start $sys_datatype_expl as row start invisible, + sys_end $sys_datatype_expl as row end invisible, + period for system_time (sys_start, sys_end)) +with system versioning; + +insert into t1(x, y) values(33, 44); +insert into t1(id, x, y) values(20, 33, 44); +insert into t1 values(40, 33, 44); +replace_result $sys_datatype_max MAXVAL; +eval select id, x, y, sys_end < $sys_datatype_max from t1; + +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create or replace table t1( + x int unsigned, + y int unsigned, + sys_start $sys_datatype_expl as row start invisible, + sys_end $sys_datatype_expl as row end invisible, + period for system_time (sys_start, sys_end)) +with system versioning; +create view vt1_1 as select x, y from t1; +insert into t1(x, y) values(8001, 9001); +insert into vt1_1(x, y) values(1001, 2001); +insert into vt1_1 values(1002, 2002); +replace_result $sys_datatype_max MAXVAL; +eval select x, y, sys_end < $sys_datatype_max from t1; +select x, y from vt1_1; +drop view vt1_1; + +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create or replace table t1( id bigint primary key, a int, b int) with system versioning; +insert into t1 values(1, 1, 1); +select row_start, row_end from t1 into @sys_start, @sys_end; +select id, a, b from t1; +insert into t1 values(2, 2, 2); +select id, a, b, row_start > @sys_start as C, row_end = @sys_end as D from t1 where id = 2; +drop table t1; + +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create or replace table t1( + x int unsigned, + y int unsigned, + sys_start $sys_datatype_expl as row start invisible, + sys_end $sys_datatype_expl as row end invisible, + period for system_time (sys_start, sys_end)) +with system versioning; +create or replace table t2 like t1; +insert into t1(x, y) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000), (6, 6000), (7, 7000), (8, 8000), (9, 9000); +delete from t1 where x >= 1; +insert into t1(x, y) values (1, 1001), (2, 2001), (3, 3001), (4, 4001), (5, 5001), (6, 6001); +insert into t1(x, y, sys_start) values (7, 7001, DEFAULT); +insert into t1(x, y, sys_end) values (8, 8001, DEFAULT); +insert into t1(x, y, sys_start, sys_end) values (9, 9001, DEFAULT, DEFAULT); +insert into t2 select x, y from t1 for system_time all; +select x, y from t1; +select x, y from t2; drop table t1; drop table t2; -drop procedure test_01; -drop procedure test_02; -drop procedure test_03; -drop procedure test_04; -drop procedure test_05; - -- source suite/versioning/common_finish.inc - -# -# MDEV-14788 System versioning cannot be based on local timestamps, as it is now -# -set timestamp=1000000019; -select now() < sysdate(); -create table t1 (a int) with system versioning; -insert t1 values (1); - ---source suite/versioning/wait_system_clock.inc -set @a=sysdate(6); - -select * from t1 for system_time as of now(6); -select * from t1 for system_time as of sysdate(6); -update t1 set a=2; -delete from t1; ---sorted_result -select *, row_start > @a, row_end > @a from t1 for system_time all; - ---echo # ---echo # MDEV-14871 Server crashes in fill_record / fill_record_n_invoke_before_triggers upon inserting into versioned table with trigger ---echo # -create or replace table t1 (pk int primary key) with system versioning; -create trigger tr before insert on t1 for each row select 1 into @a; -insert into t1 values (1),(2); -drop table t1; - -# -# MDEV-14794 Limitations which the row end as a part of PK imposes due to CURRENT_TIMESTAMP behavior and otherwise -# -create table t1 (pk int primary key, i int) with system versioning; -replace into t1 values (1,10),(1,100),(1,1000); -select pk,i,row_end > '2038-01-01' from t1 for system_time all; -drop table t1; diff --git a/mysql-test/suite/versioning/t/insert2.test b/mysql-test/suite/versioning/t/insert2.test new file mode 100644 index 00000000000..b65f3c55b94 --- /dev/null +++ b/mysql-test/suite/versioning/t/insert2.test @@ -0,0 +1,104 @@ +--source include/have_innodb.inc + +# VTQ test + +create table t1( + x int unsigned, + sys_start bigint unsigned as row start invisible, + sys_end bigint unsigned as row end invisible, + period for system_time (sys_start, sys_end)) +with system versioning engine=innodb; + +create table t2(x int unsigned) engine=innodb; + +start transaction; +insert into t1(x) values(1); +commit; + +start transaction; +insert into t2(x) values(1); +savepoint a; +insert into t1(x) values(1); +rollback to a; +commit; + +insert into t2(x) values (1); + +# virtual columns +create or replace table t1 ( + x int, + y int as (x) virtual, + sys_trx_start bigint unsigned as row start invisible, + sys_trx_end bigint unsigned as row end invisible, + period for system_time (sys_trx_start, sys_trx_end) +) engine=innodb with system versioning; +insert into t1 values (1, null); +update t1 set x= x + 1; +select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_time all; + +create or replace table t1 ( + x int, + row_start timestamp(6) as row start invisible, + row_end timestamp(6) as row end invisible, + period for system_time (row_start, row_end) +) with system versioning; +insert into t1 values (1), (2); +--error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN +insert into t1 (row_start) select row_end from t1; +set sql_mode=''; +insert into t1 (row_start, row_end) values (DEFAULT, 1); +set sql_mode=default; +select @@sql_mode into @saved_mode; +set sql_mode= ''; +insert into t1 (x, row_start, row_end) values (3, 4, 5); +set sql_mode= @saved_mode; +insert into t1 (row_start, row_end) values (DEFAULT, DEFAULT); +select * from t1; + +--echo # MDEV-14792 INSERT without column list into table with explicit versioning columns produces bad data +create or replace table t1 ( + i int, + s timestamp(6) as row start, + e timestamp(6) as row end, + c varchar(8), + period for system_time(s, e)) +with system versioning; +insert into t1 values (1, null, null, 'foo'); +select i, c, e>TIMESTAMP'2038-01-01 00:00:00' AS current_row from t1; + +drop table t1; +drop table t2; + +# +# MDEV-14788 System versioning cannot be based on local timestamps, as it is now +# +set timestamp=1000000019; +select now() < sysdate(); +create table t1 (a int) with system versioning; +insert t1 values (1); + +--source suite/versioning/wait_system_clock.inc +set @a=sysdate(6); + +select * from t1 for system_time as of now(6); +select * from t1 for system_time as of sysdate(6); +update t1 set a=2; +delete from t1; +--sorted_result +select *, row_start > @a, row_end > @a from t1 for system_time all; + +--echo # +--echo # MDEV-14871 Server crashes in fill_record / fill_record_n_invoke_before_triggers upon inserting into versioned table with trigger +--echo # +create or replace table t1 (pk int primary key) with system versioning; +create trigger tr before insert on t1 for each row select 1 into @a; +insert into t1 values (1),(2); +drop table t1; + +# +# MDEV-14794 Limitations which the row end as a part of PK imposes due to CURRENT_TIMESTAMP behavior and otherwise +# +create table t1 (pk int primary key, i int) with system versioning; +replace into t1 values (1,10),(1,100),(1,1000); +select pk,i,row_end > '2038-01-01' from t1 for system_time all; +drop table t1; diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test index e3ecdeaeea0..12fea2b86c2 100644 --- a/mysql-test/suite/versioning/t/partition.test +++ b/mysql-test/suite/versioning/t/partition.test @@ -96,7 +96,7 @@ alter table t1 add partition ( alter table t1 add partition ( partition p1 history); ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t1; insert into t1 values (1), (2); @@ -202,7 +202,7 @@ partition by system_time limit 2 ( partition p1 history, partition pn current); ---replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE +--replace_result $default_engine DEFAULT_ENGINE show create table t1; --error ER_DROP_PARTITION_NON_EXISTENT diff --git a/mysql-test/suite/versioning/t/select2.test b/mysql-test/suite/versioning/t/select2.test index 7baaec3bced..bedda892c82 100644 --- a/mysql-test/suite/versioning/t/select2.test +++ b/mysql-test/suite/versioning/t/select2.test @@ -1,17 +1,14 @@ --source suite/versioning/engines.inc --source suite/versioning/common.inc -let $engine=`select default_engine()`; -let $sys_type=`select sys_datatype(default_engine())`; - -replace_result $engine ENGINE $sys_type SYS_TYPE; +replace_result $default_engine ENGINE $sys_datatype_expl SYS_TYPE; eval create table t1( x int unsigned, y int unsigned, - sys_start $sys_type as row start invisible, - sys_end $sys_type as row end invisible, + sys_start $sys_datatype_expl as row start invisible, + sys_end $sys_datatype_expl as row end invisible, period for system_time (sys_start, sys_end)) -with system versioning engine=$engine; +with system versioning engine=$default_engine; insert into t1 (x, y) values (0, 100), @@ -32,7 +29,7 @@ delete from t1 where x > 7; insert into t1(x, y) values(3, 33); select sys_start from t1 where x = 3 and y = 33 into @t1; -if(`select '$engine' = 'innodb'`) { +if($MTR_COMBINATION_TRX_ID) { set @x1= @t1; select vtq_commit_ts(@x1) into @t1; } @@ -43,12 +40,12 @@ select x as FROMTO_x, y from t1 for system_time from '0-0-0 0:0:0' to timestamp select x as BETWAND_x, y from t1 for system_time between '0-0-0 0:0:0' and timestamp @t1; select x as ALL_x, y from t1 for system_time all; -if(`select '$engine' = 'innodb'`) { +if($MTR_COMBINATION_TRX_ID) { select x as ASOF2_x, y from t1 for system_time as of @x0; select x as FROMTO2_x, y from t1 for system_time from @x0 to @x1; select x as BETWAND2_x, y from t1 for system_time between transaction @x0 and transaction @x1; } -if(`select '$engine' != 'innodb'`) { +if(!$MTR_COMBINATION_TRX_ID) { select x as ASOF2_x, y from t1 for system_time as of @t0; select x as FROMTO2_x, y from t1 for system_time from '0-0-0 0:0:0' to @t1; select x as BETWAND2_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1; @@ -56,14 +53,14 @@ if(`select '$engine' != 'innodb'`) { drop table t1; -replace_result $engine ENGINE $sys_type SYS_TYPE; +replace_result $default_engine ENGINE $sys_datatype_expl SYS_TYPE; eval create table t1( x int, y int, - sys_start $sys_type as row start invisible, - sys_end $sys_type as row end invisible, + sys_start $sys_datatype_expl as row start invisible, + sys_end $sys_datatype_expl as row end invisible, period for system_time (sys_start, sys_end)) -with system versioning engine=$engine; +with system versioning engine=$default_engine; create table t2 like t1; diff --git a/mysql-test/suite/versioning/t/update.test b/mysql-test/suite/versioning/t/update.test index 5a3034e5cae..67d7db952ae 100644 --- a/mysql-test/suite/versioning/t/update.test +++ b/mysql-test/suite/versioning/t/update.test @@ -1,309 +1,150 @@ ---source suite/versioning/common.inc +source suite/versioning/engines.inc; +source suite/versioning/common.inc; -delimiter ~~; -create procedure test_01( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat(' - create table t1( +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create table t1( x int unsigned, y int unsigned, - sys_trx_start ', sys_type, ' as row start invisible, - sys_trx_end ', sys_type, ' as row end invisible, + sys_trx_start $sys_datatype_expl as row start invisible, + sys_trx_end $sys_datatype_expl as row end invisible, period for system_time (sys_trx_start, sys_trx_end)) - with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; - insert into t1(x, y) values - (1, 1000), - (2, 2000), - (3, 3000), - (4, 4000), - (5, 5000), - (6, 6000), - (7, 7000), - (8, 8000), - (9, 9000); - select x, y from t1; - update t1 set y = y + 1 where x > 7; - select x, y from t1; - select x, y from t1 for system_time - between timestamp '0000-0-0 0:0:0' - and timestamp '2038-01-19 04:14:07'; - drop table t1; -end~~ + with system versioning; -create procedure test_02( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat(' - create table t1 ( - id bigint primary key, - x int, - y int without system versioning, - sys_trx_start ', sys_type, ' as row start invisible, - sys_trx_end ', sys_type, ' as row end invisible, - period for system_time (sys_trx_start, sys_trx_end)) - with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; - insert into t1 values(1, 1, 1); - set @ins_t= now(6); - select sys_trx_start into @tmp1 from t1; - update t1 set x= 11, y= 11 where id = 1; - select @tmp1 < sys_trx_start as A1, x, y from t1; - - select sys_trx_start into @tmp1 from t1; - update t1 set y= 1 where id = 1; - select @tmp1 = sys_trx_start as A2, x from t1; +insert into t1(x, y) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000), (6, 6000), (7, 7000), (8, 8000), (9, 9000); +select x, y from t1; +update t1 set y = y + 1 where x > 7; +select x, y from t1; +select x, y from t1 for system_time all; +drop table t1; - drop table t1; -end~~ +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create table t1 ( + id bigint primary key, + x int, + y int without system versioning, + sys_trx_start $sys_datatype_expl as row start invisible, + sys_trx_end $sys_datatype_expl as row end invisible, + period for system_time (sys_trx_start, sys_trx_end)) +with system versioning; +insert into t1 values(1, 1, 1); +set @ins_t= now(6); +select sys_trx_start into @tmp1 from t1; +update t1 set x= 11, y= 11 where id = 1; +select @tmp1 < sys_trx_start as A1, x, y from t1; +select sys_trx_start into @tmp1 from t1; +update t1 set y= 1 where id = 1; +select @tmp1 = sys_trx_start as A2, x from t1; +drop table t1; -create procedure test_03( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat(' - create table t1 ( - x int, - y int, - sys_trx_start bigint unsigned as row start invisible, - sys_trx_end bigint unsigned as row end invisible, - period for system_time (sys_trx_start, sys_trx_end) - ) with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create table t1 ( + x int, + y int, + sys_trx_start $sys_datatype_expl as row start invisible, + sys_trx_end $sys_datatype_expl as row end invisible, + period for system_time (sys_trx_start, sys_trx_end) +) with system versioning; - insert into t1 (x, y) values (1, 1), (2, 1), (3, 1), (4, 1), (5, 1); +insert into t1 (x, y) values (1, 1), (2, 1), (3, 1), (4, 1), (5, 1); - start transaction; - update t1 set y= y + 1 where x = 3; - update t1 set y= y + 1 where x = 2; - update t1 set y= y + 1 where x = 3; - update t1 set y= y + 1 where x > 3; - update t1 set y= y + 1 where x > 4; - commit; +start transaction; +update t1 set y= y + 1 where x = 3; +update t1 set y= y + 1 where x = 2; +update t1 set y= y + 1 where x = 3; +update t1 set y= y + 1 where x > 3; +update t1 set y= y + 1 where x > 4; +commit; - select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_time all; +replace_result $sys_datatype_max MAXVAL; +eval select x, y, sys_trx_end = $sys_datatype_max as current from t1 for system_time all; - drop table t1; -end~~ +drop table t1; -create procedure test_04( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat(' - create table t1 ( - id int primary key auto_increment, - x int, - sys_trx_start ', sys_type, ' as row start invisible, - sys_trx_end ', sys_type, ' as row end invisible, - period for system_time (sys_trx_start, sys_trx_end)) - with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create table t1 ( + id int primary key auto_increment, + x int, + sys_trx_start $sys_datatype_expl as row start invisible, + sys_trx_end $sys_datatype_expl as row end invisible, + period for system_time (sys_trx_start, sys_trx_end)) +with system versioning; - set @t0= now(6); - insert into t1 (x) values (1); - set @t1= now(6); - update t1 set x= 2 where id = 1; - set @t2= now(6); - update t1 set x= 3 where id = 1; +set @t0= now(6); +insert into t1 (x) values (1); +set @t1= now(6); +update t1 set x= 2 where id = 1; +set @t2= now(6); +update t1 set x= 3 where id = 1; - select x from t1 for system_time as of timestamp @t0; - select x from t1 for system_time as of timestamp @t1; - select x from t1 for system_time as of timestamp @t2; - select x from t1 for system_time as of timestamp now(6); +select x from t1 for system_time as of timestamp @t0; +select x from t1 for system_time as of timestamp @t1; +select x from t1 for system_time as of timestamp @t2; +select x from t1 for system_time as of timestamp now(6); - drop table t1; -end~~ +drop table t1; -create procedure test_05( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat(' - create table t1( - x int unsigned, - sys_trx_end ', sys_type, ' as row end invisible, - sys_trx_start ', sys_type, ' as row start invisible, - y int unsigned, - period for system_time (sys_trx_start, sys_trx_end), - primary key(x, y)) - with system versioning - engine ', engine); - prepare stmt from @str; execute stmt; drop prepare stmt; - insert into t1(x, y) values - (1, 1000), - (3, 3000), - (4, 4000), - (5, 5000); - insert into t1(x, y) values(3, 3000) on duplicate key update y = y+1; - insert into t1(x, y) values(4, 4444) on duplicate key update y = y+1; - select x, y from t1 for system_time all; - select x, y from t1; - drop table t1; -end~~ +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create table t1( + x int unsigned, + sys_trx_end $sys_datatype_expl as row end invisible, + sys_trx_start $sys_datatype_expl as row start invisible, + y int unsigned, + period for system_time (sys_trx_start, sys_trx_end), + primary key(x, y)) +with system versioning; +insert into t1(x, y) values (1, 1000), (3, 3000), (4, 4000), (5, 5000); +insert into t1(x, y) values(3, 3000) on duplicate key update y = y+1; +insert into t1(x, y) values(4, 4444) on duplicate key update y = y+1; +select x, y from t1 for system_time all; +select x, y from t1; +drop table t1; -create procedure test_06( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat('( +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create table t1 ( x int unsigned, y int unsigned, - sys_trx_start ', sys_type, ' as row start invisible, - sys_trx_end ', sys_type, ' as row end invisible, + sys_trx_start $sys_datatype_expl as row start invisible, + sys_trx_end $sys_datatype_expl as row end invisible, period for system_time (sys_trx_start, sys_trx_end)) - with system versioning - engine ', engine); - set @str2= concat('create table t1', @str); - prepare stmt from @str2; execute stmt; drop prepare stmt; - set @str2= concat('create table t2', @str); - prepare stmt from @str2; execute stmt; drop prepare stmt; - insert into t1(x, y) values - (1, 1000), - (2, 2000), - (3, 3000), - (4, 4000), - (5, 5000), - (6, 6000), - (7, 7000), - (8, 8000), - (9, 9000); - insert into t2(x, y) values - (1, 1010), - (2, 2010), - (3, 3010), - (4, 4010), - (5, 5010), - (6, 6010), - (7, 7010), - (8, 8010), - (9, 9010); - update t1, t2 set t1.y = t1.x + t1.y, t2.y = t2.x + t2.y where t1.x > 7 and t2.x < 7; - select x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp '9999-1-1 0:0:0'; - select x, y from t1; - select x, y from t2 for system_time between timestamp '0-0-0 0:0:0' and timestamp '9999-1-1 0:0:0'; - select x, y from t2; - drop table t1; - drop table t2; -end~~ + with system versioning; +create table t2 like t1; +insert into t1(x, y) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000), (6, 6000), (7, 7000), (8, 8000), (9, 9000); +insert into t2(x, y) values (1, 1010), (2, 2010), (3, 3010), (4, 4010), (5, 5010), (6, 6010), (7, 7010), (8, 8010), (9, 9010); +update t1, t2 set t1.y = t1.x + t1.y, t2.y = t2.x + t2.y where t1.x > 7 and t2.x < 7; +select x, y from t1 for system_time all; +select x, y from t1; +select x, y from t2 for system_time all; +select x, y from t2; +drop table t1; +drop table t2; -create procedure test_07( - sys_type varchar(255), - engine varchar(255), - fields varchar(255)) -begin - set @str= concat('( +replace_result $sys_datatype_expl SYS_DATATYPE; +eval create table t1 ( id bigint primary key without system versioning, name varchar(128), salary bigint without system versioning, - sys_trx_start ', sys_type, ' as row start invisible, - sys_trx_end ', sys_type, ' as row end invisible, + sys_trx_start $sys_datatype_expl as row start invisible, + sys_trx_end $sys_datatype_expl as row end invisible, period for system_time (sys_trx_start, sys_trx_end)) - with system versioning - engine ', engine); + with system versioning; +create table t2 like t1; - set @str2= concat('create table t1', @str); - prepare stmt from @str2; execute stmt; drop prepare stmt; - set @str2= concat('create table t2', @str); - prepare stmt from @str2; execute stmt; drop prepare stmt; +insert into t1 values (1, "Jeremy", 3000); +insert into t2 values (1, "Jeremy", 4000); - insert into t1 values (1, "Jeremy", 3000); - insert into t2 values (1, "Jeremy", 4000); - - select sys_trx_start into @tmp1 from t1; - select sys_trx_start into @tmp2 from t2; - update t1, t2 set t1.name= "Jerry", t2.name= "Jerry" where t1.id = t2.id and t1.name = "Jeremy"; - select @tmp1 < sys_trx_start as A1, name from t1; - select @tmp2 < sys_trx_start as A2, name from t2; - - select sys_trx_start into @tmp1 from t1; - select sys_trx_start into @tmp2 from t2; - update t1, t2 set t1.salary= 2500, t2.salary= 2500 where t1.id = t2.id and t1.name = "Jerry"; - select @tmp1 = sys_trx_start as B1, salary from t1; - select @tmp2 = sys_trx_start as B2, salary from t2; +select sys_trx_start into @tmp1 from t1; +select sys_trx_start into @tmp2 from t2; +update t1, t2 set t1.name= "Jerry", t2.name= "Jerry" where t1.id = t2.id and t1.name = "Jeremy"; +select @tmp1 < sys_trx_start as A1, name from t1; +select @tmp2 < sys_trx_start as A2, name from t2; - drop table t1; - drop table t2; -end~~ -delimiter ;~~ +select sys_trx_start into @tmp1 from t1; +select sys_trx_start into @tmp2 from t2; +update t1, t2 set t1.salary= 2500, t2.salary= 2500 where t1.id = t2.id and t1.name = "Jerry"; +select @tmp1 = sys_trx_start as B1, salary from t1; +select @tmp2 = sys_trx_start as B2, salary from t2; -call test_01('timestamp(6)', 'myisam', 'sys_trx_end'); -call test_01('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call verify_vtq; +drop table t1; +drop table t2; -call test_02('timestamp(6)', 'myisam', 'sys_trx_end'); -call test_02('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call test_02('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call verify_vtq; - ---echo # Multiple UPDATE of same rows in single transaction create historical ---echo # rows only once (applicable to transaction-based only). -call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call verify_vtq; - -call test_04('timestamp(6)', 'myisam', 'sys_trx_end'); -call test_04('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call test_04('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call verify_vtq; - -call test_05('timestamp(6)', 'myisam', 'sys_trx_end'); -call test_05('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call test_05('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call verify_vtq; - -call test_06('timestamp(6)', 'myisam', 'sys_trx_end'); -call test_06('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call test_06('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call verify_vtq; - ---echo # Optimized fields -call test_07('timestamp(6)', 'myisam', 'sys_trx_end'); -call test_07('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call test_07('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)'); -call verify_vtq; - ---echo ### Issue #365, bug 7 (duplicate of historical row) -create or replace table t1 (a int primary key, b int) -with system versioning engine myisam; -insert into t1 (a) values (1); - -replace t1 values (1,2),(1,3),(2,4); - -# -# MDEV-14829 Assertion `0' failed in Protocol::end_statement upon concurrent UPDATE -# - -create or replace table t1 (pk int, a char(3), b char(3), primary key(pk)) - engine=innodb with system versioning; - -insert into t1 (pk) values (1); -connect (con1,localhost,root,,test); -start transaction; -select * from t1 for update; -connection default; -send update t1 set b = 'foo'; -connection con1; -let $wait_condition= select count(*) from information_schema.innodb_lock_waits; -source include/wait_condition.inc; -error ER_LOCK_DEADLOCK; -update t1 set a = 'bar'; -disconnect con1; -connection default; -reap; - -drop database test; -create database test; +source suite/versioning/common_finish.inc; diff --git a/mysql-test/suite/versioning/t/update2.test b/mysql-test/suite/versioning/t/update2.test new file mode 100644 index 00000000000..87ca3746b12 --- /dev/null +++ b/mysql-test/suite/versioning/t/update2.test @@ -0,0 +1,31 @@ +source include/have_innodb.inc; + +echo ### Issue #365, bug 7 (duplicate of historical row); +create or replace table t1 (a int primary key, b int) +with system versioning engine myisam; +insert into t1 (a) values (1); + +replace t1 values (1,2),(1,3),(2,4); + +# +# MDEV-14829 Assertion `0' failed in Protocol::end_statement upon concurrent UPDATE +# + +create or replace table t1 (pk int, a char(3), b char(3), primary key(pk)) + engine=innodb with system versioning; + +insert into t1 (pk) values (1); +connect (con1,localhost,root,,test); +start transaction; +select * from t1 for update; +connection default; +send update t1 set b = 'foo'; +connection con1; +let $wait_condition= select count(*) from information_schema.innodb_lock_waits; +source include/wait_condition.inc; +error ER_LOCK_DEADLOCK; +update t1 set a = 'bar'; +disconnect con1; +connection default; +reap; +drop table t1;