Commit 75afaa7e authored by Aleksey Midenkov's avatar Aleksey Midenkov Committed by Sergei Golubchik

MDEV-15001 no tests for system_versioning_innodb_algorithm_simple

Vers SQL: TRT fix getting TRX_ID by COMMIT_TS

Fixed wrong assumption that records are ordered by COMMIT_TS.
This is anyway a quick hack until tempesta-tech#314 is done.

See also FIXME and TODO in TR_table::query(MYSQL_TIME, bool).

Test: SEES case for trx_id.test [closes #456]
parent e36c5ec0
...@@ -57,10 +57,12 @@ not vtq_trx_sees(@tx0, @tx1) as B, ...@@ -57,10 +57,12 @@ not vtq_trx_sees(@tx0, @tx1) as B,
vtq_trx_sees_eq(@tx1, @tx1) as C, vtq_trx_sees_eq(@tx1, @tx1) as C,
not vtq_trx_sees(@tx1, @tx1) as D, not vtq_trx_sees(@tx1, @tx1) as D,
vtq_trx_sees(@tx2, 0) as E, vtq_trx_sees(@tx2, 0) as E,
vtq_trx_sees(0, @tx2) is null as F, vtq_trx_sees(-1, @tx2) as F;
vtq_trx_sees(-1, @tx2) as H; A B C D E F
A B C D E F H 1 1 1 1 1 1
1 1 1 1 1 1 1 select vtq_trx_sees(0, @tx2);
vtq_trx_sees(0, @tx2)
NULL
set transaction isolation level read uncommitted; set transaction isolation level read uncommitted;
insert into t1 values (); insert into t1 values ();
select sys_trx_start from t1 where id = last_insert_id() into @tx3; select sys_trx_start from t1 where id = last_insert_id() into @tx3;
......
...@@ -65,4 +65,93 @@ alter table t1 drop column sys_start, drop column sys_end; ...@@ -65,4 +65,93 @@ 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;
transaction_based transaction_based
1 1
# Simple vs SEES algorithms
create or replace table t1 (
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;
set transaction isolation level read committed;
start transaction;
insert into t1 values (1);
connect con1,localhost,root,,test;
set transaction isolation level read committed;
start transaction;
insert into t1 values (2);
connect con2,localhost,root,,test;
set transaction isolation level read committed;
start transaction;
insert into t1 values (3);
commit;
disconnect con2;
connection default;
set @ts1= sysdate(6);
connection con1;
commit;
disconnect con1;
connection default;
set @ts2= sysdate(6);
commit;
set @ts3= sysdate(6);
select sys_start from t1 where x = 1 into @trx_id1;
select sys_start from t1 where x = 2 into @trx_id2;
select sys_start from t1 where x = 3 into @trx_id3;
select @trx_id1 < @trx_id2, @trx_id2 < @trx_id3;
@trx_id1 < @trx_id2 @trx_id2 < @trx_id3
1 1
select @ts1 < @ts2, @ts2 < @ts3;
@ts1 < @ts2 @ts2 < @ts3
1 1
# MVCC is not resolved
select * from t1 for system_time as of transaction @trx_id1;
x
1
select * from t1 for system_time as of timestamp @ts1;
x
3
select * from t1 for system_time as of transaction @trx_id2;
x
1
2
select * from t1 for system_time as of timestamp @ts2;
x
2
3
select * from t1 for system_time as of transaction @trx_id3;
x
1
2
3
select * from t1 for system_time as of timestamp @ts3;
x
1
2
3
set system_versioning_innodb_algorithm_simple= off;
# MVCC is resolved
select * from t1 for system_time as of transaction @trx_id1;
x
1
2
3
select * from t1 for system_time as of timestamp @ts1;
x
3
select * from t1 for system_time as of transaction @trx_id2;
x
2
3
select * from t1 for system_time as of timestamp @ts2;
x
2
3
select * from t1 for system_time as of transaction @trx_id3;
x
3
select * from t1 for system_time as of timestamp @ts3;
x
1
2
3
drop table t1; drop table t1;
...@@ -61,9 +61,9 @@ select ...@@ -61,9 +61,9 @@ select
vtq_trx_sees_eq(@tx1, @tx1) as C, vtq_trx_sees_eq(@tx1, @tx1) as C,
not vtq_trx_sees(@tx1, @tx1) as D, not vtq_trx_sees(@tx1, @tx1) as D,
vtq_trx_sees(@tx2, 0) as E, vtq_trx_sees(@tx2, 0) as E,
vtq_trx_sees(0, @tx2) is null as F, vtq_trx_sees(-1, @tx2) as F;
vtq_trx_sees(-1, @tx2) as H;
select vtq_trx_sees(0, @tx2);
# VTQ_ISO_LEVEL # # VTQ_ISO_LEVEL #
......
...@@ -67,4 +67,62 @@ insert into t1 values (1); ...@@ -67,4 +67,62 @@ 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;
--echo # Simple vs SEES algorithms
create or replace table t1 (
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;
set transaction isolation level read committed;
start transaction;
insert into t1 values (1);
--connect (con1,localhost,root,,test)
set transaction isolation level read committed;
start transaction;
insert into t1 values (2);
--connect (con2,localhost,root,,test)
set transaction isolation level read committed;
start transaction;
insert into t1 values (3);
commit;
--disconnect con2
--connection default
--sleep 0.01
set @ts1= sysdate(6);
--connection con1
commit;
--disconnect con1
--connection default
--sleep 0.01
set @ts2= sysdate(6);
commit;
--sleep 0.01
set @ts3= sysdate(6);
select sys_start from t1 where x = 1 into @trx_id1;
select sys_start from t1 where x = 2 into @trx_id2;
select sys_start from t1 where x = 3 into @trx_id3;
select @trx_id1 < @trx_id2, @trx_id2 < @trx_id3;
select @ts1 < @ts2, @ts2 < @ts3;
--echo # MVCC is not resolved
select * from t1 for system_time as of transaction @trx_id1;
select * from t1 for system_time as of timestamp @ts1;
select * from t1 for system_time as of transaction @trx_id2;
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;
set system_versioning_innodb_algorithm_simple= off;
--echo # MVCC is resolved
select * from t1 for system_time as of transaction @trx_id1;
select * from t1 for system_time as of timestamp @ts1;
select * from t1 for system_time as of transaction @trx_id2;
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; drop table t1;
...@@ -8692,27 +8692,41 @@ bool TR_table::query(MYSQL_TIME &commit_time, bool backwards) ...@@ -8692,27 +8692,41 @@ bool TR_table::query(MYSQL_TIME &commit_time, bool backwards)
1 /* use_record_cache */, true /* print_error */, 1 /* use_record_cache */, true /* print_error */,
false /* disable_rr_cache */); false /* disable_rr_cache */);
// With PK by transaction_id the records are ordered by PK // With PK by transaction_id the records are ordered by PK, so we have to
// scan TRT fully and collect min (backwards == true)
// or max (backwards == false) stats.
bool found= false; bool found= false;
MYSQL_TIME found_ts;
while (!(error= info.read_record()) && !thd->killed && !thd->is_error()) while (!(error= info.read_record()) && !thd->killed && !thd->is_error())
{ {
if (select->skip_record(thd) > 0) int res= select->skip_record(thd);
if (res > 0)
{ {
if (backwards) MYSQL_TIME commit_ts;
return true; if ((*this)[FLD_COMMIT_TS]->get_date(&commit_ts, 0))
{
found= false;
break;
}
int c;
if (!found || ((c= my_time_compare(&commit_ts, &found_ts)) &&
(backwards ? c < 0 : c > 0)))
{
found_ts= commit_ts;
found= true; found= true;
// TODO: (performance) make ORDER DESC and break after first found. // TODO: (performance) make ORDER DESC and break after first found.
// Otherwise it is O(n) scan (+copy)! // Otherwise it is O(n) scan (+copy)!
store_record(table, record[1]); store_record(table, record[1]);
} }
else }
else if (res < 0)
{ {
if (found) found= false;
restore_record(table, record[1]);
if (!backwards)
break; break;
} }
} }
if (found)
restore_record(table, record[1]);
return found; return found;
} }
#undef newx #undef newx
......
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