Commit 72dd813f authored by Aleksey Midenkov's avatar Aleksey Midenkov Committed by Sergei Golubchik

MDEV-15427 IB: TRX_ID based operations inside transaction generate history

[closes tempesta-tech#472]
parent a4251d6f
set default_storage_engine= innodb;
create or replace table t1 ( create or replace table t1 (
x int, x int,
sys_trx_start bigint(20) unsigned as row start invisible, sys_trx_start bigint(20) unsigned as row start invisible,
sys_trx_end bigint(20) unsigned as row end invisible, sys_trx_end bigint(20) unsigned as row end invisible,
period for system_time (sys_trx_start, sys_trx_end) period for system_time (sys_trx_start, sys_trx_end)
) with system versioning engine innodb; ) with system versioning;
insert into t1 (x) values (1); insert into t1 (x) values (1);
# ALTER ADD SYSTEM VERSIONING should write to mysql.transaction_registry # ALTER ADD SYSTEM VERSIONING should write to mysql.transaction_registry
set @@system_versioning_alter_history=keep; 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); insert into t1 values (1);
alter table t1 alter table t1
add column s bigint unsigned as row start, add column s bigint unsigned as row start,
...@@ -19,7 +20,7 @@ select s from t1 into @trx_start; ...@@ -19,7 +20,7 @@ select s from t1 into @trx_start;
select count(*) = 1 from mysql.transaction_registry where transaction_id = @trx_start; select count(*) = 1 from mysql.transaction_registry where transaction_id = @trx_start;
count(*) = 1 count(*) = 1
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; select count(*) from mysql.transaction_registry into @tmp;
alter table t1 alter table t1
add column s bigint unsigned as row start, add column s bigint unsigned as row start,
...@@ -30,7 +31,7 @@ algorithm=inplace; ...@@ -30,7 +31,7 @@ algorithm=inplace;
select count(*) = @tmp from mysql.transaction_registry; select count(*) = @tmp from mysql.transaction_registry;
count(*) = @tmp count(*) = @tmp
1 1
create or replace table t1 (x int) engine innodb; create or replace table t1 (x int);
insert into t1 values (1); insert into t1 values (1);
alter table t1 alter table t1
add column s bigint unsigned as row start, add column s bigint unsigned as row start,
...@@ -42,7 +43,7 @@ select s from t1 into @trx_start; ...@@ -42,7 +43,7 @@ select s from t1 into @trx_start;
select count(*) = 1 from mysql.transaction_registry where transaction_id = @trx_start; select count(*) = 1 from mysql.transaction_registry where transaction_id = @trx_start;
count(*) = 1 count(*) = 1
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; select count(*) from mysql.transaction_registry into @tmp;
alter table t1 alter table t1
add column s bigint unsigned as row start, add column s bigint unsigned as row start,
...@@ -59,7 +60,7 @@ x int, ...@@ -59,7 +60,7 @@ x int,
sys_start bigint unsigned as row start invisible, sys_start bigint unsigned as row start invisible,
sys_end bigint unsigned as row end invisible, sys_end bigint unsigned as row end invisible,
period for system_time (sys_start, sys_end) period for system_time (sys_start, sys_end)
) engine innodb with system versioning; ) with system versioning;
insert into t1 values (1); insert into t1 values (1);
alter table t1 drop column sys_start, drop column sys_end; alter table t1 drop column sys_start, drop column sys_end;
select row_end = 18446744073709551615 as transaction_based from t1 for system_time all; select row_end = 18446744073709551615 as transaction_based from t1 for system_time all;
...@@ -71,7 +72,7 @@ x int, ...@@ -71,7 +72,7 @@ x int,
sys_start bigint(20) unsigned as row start invisible, sys_start bigint(20) unsigned as row start invisible,
sys_end bigint(20) unsigned as row end invisible, sys_end bigint(20) unsigned as row end invisible,
period for system_time (sys_start, sys_end) period for system_time (sys_start, sys_end)
) with system versioning engine innodb; ) with system versioning;
set transaction isolation level read committed; set transaction isolation level read committed;
start transaction; start transaction;
insert into t1 values (1); insert into t1 values (1);
...@@ -128,4 +129,29 @@ x ...@@ -128,4 +129,29 @@ x
1 1
2 2
3 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;
-- source include/have_innodb.inc -- source include/have_innodb.inc
-- source include/not_embedded.inc -- source include/not_embedded.inc
set default_storage_engine= innodb;
create or replace table t1 ( create or replace table t1 (
x int, x int,
sys_trx_start bigint(20) unsigned as row start invisible, sys_trx_start bigint(20) unsigned as row start invisible,
sys_trx_end bigint(20) unsigned as row end invisible, sys_trx_end bigint(20) unsigned as row end invisible,
period for system_time (sys_trx_start, sys_trx_end) period for system_time (sys_trx_start, sys_trx_end)
) with system versioning engine innodb; ) with system versioning;
insert into t1 (x) values (1); insert into t1 (x) values (1);
--echo # ALTER ADD SYSTEM VERSIONING should write to mysql.transaction_registry --echo # ALTER ADD SYSTEM VERSIONING should write to mysql.transaction_registry
set @@system_versioning_alter_history=keep; 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); insert into t1 values (1);
alter table t1 alter table t1
add column s bigint unsigned as row start, add column s bigint unsigned as row start,
...@@ -24,7 +26,7 @@ alter table t1 ...@@ -24,7 +26,7 @@ alter table t1
select s from t1 into @trx_start; select s from t1 into @trx_start;
select count(*) = 1 from mysql.transaction_registry where transaction_id = @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; select count(*) from mysql.transaction_registry into @tmp;
alter table t1 alter table t1
add column s bigint unsigned as row start, add column s bigint unsigned as row start,
...@@ -34,7 +36,7 @@ alter table t1 ...@@ -34,7 +36,7 @@ alter table t1
algorithm=inplace; algorithm=inplace;
select count(*) = @tmp from mysql.transaction_registry; 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); insert into t1 values (1);
alter table t1 alter table t1
add column s bigint unsigned as row start, add column s bigint unsigned as row start,
...@@ -45,7 +47,7 @@ alter table t1 ...@@ -45,7 +47,7 @@ alter table t1
select s from t1 into @trx_start; select s from t1 into @trx_start;
select count(*) = 1 from mysql.transaction_registry where transaction_id = @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; select count(*) from mysql.transaction_registry into @tmp;
alter table t1 alter table t1
add column s bigint unsigned as row start, add column s bigint unsigned as row start,
...@@ -62,7 +64,7 @@ create or replace table t1 ( ...@@ -62,7 +64,7 @@ create or replace table t1 (
sys_start bigint unsigned as row start invisible, sys_start bigint unsigned as row start invisible,
sys_end bigint unsigned as row end invisible, sys_end bigint unsigned as row end invisible,
period for system_time (sys_start, sys_end) period for system_time (sys_start, sys_end)
) engine innodb with system versioning; ) with system versioning;
insert into t1 values (1); insert into t1 values (1);
alter table t1 drop column sys_start, drop column sys_end; alter table t1 drop column sys_start, drop column sys_end;
select row_end = 18446744073709551615 as transaction_based from t1 for system_time all; select row_end = 18446744073709551615 as transaction_based from t1 for system_time all;
...@@ -73,7 +75,7 @@ create or replace table t1 ( ...@@ -73,7 +75,7 @@ create or replace table t1 (
sys_start bigint(20) unsigned as row start invisible, sys_start bigint(20) unsigned as row start invisible,
sys_end bigint(20) unsigned as row end invisible, sys_end bigint(20) unsigned as row end invisible,
period for system_time (sys_start, sys_end) period for system_time (sys_start, sys_end)
) with system versioning engine innodb; ) with system versioning;
set transaction isolation level read committed; set transaction isolation level read committed;
start transaction; start transaction;
...@@ -116,4 +118,28 @@ select * from t1 for system_time as of timestamp @ts2; ...@@ -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 transaction @trx_id3;
select * from t1 for system_time as of timestamp @ts3; 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;
...@@ -6403,11 +6403,9 @@ void TABLE::mark_columns_needed_for_delete() ...@@ -6403,11 +6403,9 @@ void TABLE::mark_columns_needed_for_delete()
if (need_signal) if (need_signal)
file->column_bitmaps_signal(); file->column_bitmaps_signal();
/*
For System Versioning we have to write and read Sys_end.
*/
if (s->versioned) 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(read_set, s->vers_end_field()->field_index);
bitmap_set_bit(write_set, s->vers_end_field()->field_index); bitmap_set_bit(write_set, s->vers_end_field()->field_index);
} }
......
...@@ -8948,6 +8948,7 @@ ha_innobase::delete_row( ...@@ -8948,6 +8948,7 @@ ha_innobase::delete_row(
/* This is a delete */ /* This is a delete */
m_prebuilt->upd_node->is_delete = table->versioned_write(VERS_TRX_ID) m_prebuilt->upd_node->is_delete = table->versioned_write(VERS_TRX_ID)
&& table->vers_end_field()->is_max() && table->vers_end_field()->is_max()
&& trx->id != table->vers_start_id()
? VERSIONED_DELETE ? VERSIONED_DELETE
: PLAIN_DELETE; : PLAIN_DELETE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment