diff --git a/mysql-test/suite/versioning/r/trx_id.result b/mysql-test/suite/versioning/r/trx_id.result index 30ca278eaea..c8c9b69ca15 100644 --- a/mysql-test/suite/versioning/r/trx_id.result +++ b/mysql-test/suite/versioning/r/trx_id.result @@ -1,13 +1,14 @@ +set default_storage_engine= innodb; create or replace table t1 ( x int, sys_trx_start bigint(20) unsigned as row start invisible, sys_trx_end bigint(20) unsigned as row end invisible, period for system_time (sys_trx_start, sys_trx_end) -) with system versioning engine innodb; +) with system versioning; insert into t1 (x) values (1); # ALTER ADD SYSTEM VERSIONING should write to mysql.transaction_registry set @@system_versioning_alter_history=keep; -create or replace table t1 (x int) engine innodb; +create or replace table t1 (x int); insert into t1 values (1); alter table t1 add column s bigint unsigned as row start, @@ -19,7 +20,7 @@ select s from t1 into @trx_start; select count(*) = 1 from mysql.transaction_registry where transaction_id = @trx_start; count(*) = 1 1 -create or replace table t1 (x int) engine innodb; +create or replace table t1 (x int); select count(*) from mysql.transaction_registry into @tmp; alter table t1 add column s bigint unsigned as row start, @@ -30,7 +31,7 @@ algorithm=inplace; select count(*) = @tmp from mysql.transaction_registry; count(*) = @tmp 1 -create or replace table t1 (x int) engine innodb; +create or replace table t1 (x int); insert into t1 values (1); alter table t1 add column s bigint unsigned as row start, @@ -42,7 +43,7 @@ select s from t1 into @trx_start; select count(*) = 1 from mysql.transaction_registry where transaction_id = @trx_start; count(*) = 1 1 -create or replace table t1 (x int) engine innodb; +create or replace table t1 (x int); select count(*) from mysql.transaction_registry into @tmp; alter table t1 add column s bigint unsigned as row start, @@ -59,7 +60,7 @@ x int, sys_start bigint unsigned as row start invisible, sys_end bigint unsigned as row end invisible, period for system_time (sys_start, sys_end) -) engine innodb with system versioning; +) with system versioning; insert into t1 values (1); alter table t1 drop column sys_start, drop column sys_end; select row_end = 18446744073709551615 as transaction_based from t1 for system_time all; @@ -71,7 +72,7 @@ x int, sys_start bigint(20) unsigned as row start invisible, sys_end bigint(20) unsigned as row end invisible, period for system_time (sys_start, sys_end) -) with system versioning engine innodb; +) with system versioning; set transaction isolation level read committed; start transaction; insert into t1 values (1); @@ -128,4 +129,29 @@ x 1 2 3 -drop table t1; +# +# MDEV-15427 IB: TRX_ID based operations inside transaction generate history +# +create or replace table t1( +x int(10), +row_start bigint(20) unsigned as row start, +row_end bigint(20) unsigned as row end, +period for system_time(row_start, row_end) +) with system versioning; +begin; +insert into t1 (x) values (1); +delete from t1; +commit; +select x from t1 for system_time all; +x +insert into t1 (x) values (2); +begin; +update t1 set x= 3; +update t1 set x= 4; +commit; +select x, row_start < row_end from t1 for system_time all; +x row_start < row_end +4 1 +2 1 +drop database test; +create database test; diff --git a/mysql-test/suite/versioning/t/trx_id.test b/mysql-test/suite/versioning/t/trx_id.test index f1dbbf66cae..45d453dc7d0 100644 --- a/mysql-test/suite/versioning/t/trx_id.test +++ b/mysql-test/suite/versioning/t/trx_id.test @@ -1,19 +1,21 @@ -- source include/have_innodb.inc -- source include/not_embedded.inc +set default_storage_engine= innodb; + create or replace table t1 ( x int, sys_trx_start bigint(20) unsigned as row start invisible, sys_trx_end bigint(20) unsigned as row end invisible, period for system_time (sys_trx_start, sys_trx_end) -) with system versioning engine innodb; +) with system versioning; insert into t1 (x) values (1); --echo # ALTER ADD SYSTEM VERSIONING should write to mysql.transaction_registry set @@system_versioning_alter_history=keep; -create or replace table t1 (x int) engine innodb; +create or replace table t1 (x int); insert into t1 values (1); alter table t1 add column s bigint unsigned as row start, @@ -24,7 +26,7 @@ alter table t1 select s from t1 into @trx_start; select count(*) = 1 from mysql.transaction_registry where transaction_id = @trx_start; -create or replace table t1 (x int) engine innodb; +create or replace table t1 (x int); select count(*) from mysql.transaction_registry into @tmp; alter table t1 add column s bigint unsigned as row start, @@ -34,7 +36,7 @@ alter table t1 algorithm=inplace; select count(*) = @tmp from mysql.transaction_registry; -create or replace table t1 (x int) engine innodb; +create or replace table t1 (x int); insert into t1 values (1); alter table t1 add column s bigint unsigned as row start, @@ -45,7 +47,7 @@ alter table t1 select s from t1 into @trx_start; select count(*) = 1 from mysql.transaction_registry where transaction_id = @trx_start; -create or replace table t1 (x int) engine innodb; +create or replace table t1 (x int); select count(*) from mysql.transaction_registry into @tmp; alter table t1 add column s bigint unsigned as row start, @@ -62,7 +64,7 @@ create or replace table t1 ( sys_start bigint unsigned as row start invisible, sys_end bigint unsigned as row end invisible, period for system_time (sys_start, sys_end) -) engine innodb with system versioning; +) with system versioning; insert into t1 values (1); alter table t1 drop column sys_start, drop column sys_end; select row_end = 18446744073709551615 as transaction_based from t1 for system_time all; @@ -73,7 +75,7 @@ create or replace table t1 ( sys_start bigint(20) unsigned as row start invisible, sys_end bigint(20) unsigned as row end invisible, period for system_time (sys_start, sys_end) -) with system versioning engine innodb; +) with system versioning; set transaction isolation level read committed; start transaction; @@ -116,4 +118,28 @@ select * from t1 for system_time as of timestamp @ts2; select * from t1 for system_time as of transaction @trx_id3; select * from t1 for system_time as of timestamp @ts3; -drop table t1; +--echo # +--echo # MDEV-15427 IB: TRX_ID based operations inside transaction generate history +--echo # +create or replace table t1( + x int(10), + row_start bigint(20) unsigned as row start, + row_end bigint(20) unsigned as row end, + period for system_time(row_start, row_end) +) with system versioning; + +begin; +insert into t1 (x) values (1); +delete from t1; +commit; +select x from t1 for system_time all; + +insert into t1 (x) values (2); +begin; +update t1 set x= 3; +update t1 set x= 4; +commit; +select x, row_start < row_end from t1 for system_time all; + +drop database test; +create database test; diff --git a/sql/table.cc b/sql/table.cc index 1e585392caf..577ed20a87e 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -6403,11 +6403,9 @@ void TABLE::mark_columns_needed_for_delete() if (need_signal) file->column_bitmaps_signal(); - /* - For System Versioning we have to write and read Sys_end. - */ if (s->versioned) { + bitmap_set_bit(read_set, s->vers_start_field()->field_index); bitmap_set_bit(read_set, s->vers_end_field()->field_index); bitmap_set_bit(write_set, s->vers_end_field()->field_index); } diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index e67a81f1b62..d9c3995f305 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -8948,6 +8948,7 @@ ha_innobase::delete_row( /* This is a delete */ m_prebuilt->upd_node->is_delete = table->versioned_write(VERS_TRX_ID) && table->vers_end_field()->is_max() + && trx->id != table->vers_start_id() ? VERSIONED_DELETE : PLAIN_DELETE;