From fe44d46a0356128a5c97440cfab93a93f904a5e6 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 17 Oct 2022 19:09:47 +0200 Subject: [PATCH] MDEV-29721 Inconsistency upon inserting history with visible system versioning columns --- mysql-test/suite/versioning/r/misc.result | 25 +++++++++++++++++++++++ mysql-test/suite/versioning/t/misc.test | 21 +++++++++++++++++++ sql/field.cc | 6 ++++++ sql/table.cc | 5 +---- 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 mysql-test/suite/versioning/r/misc.result create mode 100644 mysql-test/suite/versioning/t/misc.test diff --git a/mysql-test/suite/versioning/r/misc.result b/mysql-test/suite/versioning/r/misc.result new file mode 100644 index 00000000000..d74bb8607ed --- /dev/null +++ b/mysql-test/suite/versioning/r/misc.result @@ -0,0 +1,25 @@ +set time_zone='+00:00'; +# +# MDEV-29721 Inconsistency upon inserting history with visible system versioning columns +# +create table t1 (a int, s timestamp(6) as row start, e timestamp(6) as row end, period for system_time(s,e)) with system versioning; +set system_versioning_insert_history=on; +set timestamp=unix_timestamp('2010-10-10 10:10:10'); +insert t1 (a,s,e) values (1,'2020-01-01',default), (2,'2020-02-02',ignore),(3,default,'2020-03-03'), (4,ignore,'2020-04-04'); +set timestamp=unix_timestamp('2010-11-11 11:11:11'); +insert t1 values (5,'2020-01-01',default), (6,'2020-02-02',ignore),(7,default,'2020-03-03'), (8,ignore,'2020-04-04'); +set timestamp=default; +select * from t1 for system_time all; +a s e +1 2020-01-01 00:00:00.000000 2038-01-19 03:14:07.999999 +2 2020-02-02 00:00:00.000000 2038-01-19 03:14:07.999999 +3 2010-10-10 10:10:10.000000 2020-03-03 00:00:00.000000 +4 2010-10-10 10:10:10.000000 2020-04-04 00:00:00.000000 +5 2020-01-01 00:00:00.000000 2038-01-19 03:14:07.999999 +6 2020-02-02 00:00:00.000000 2038-01-19 03:14:07.999999 +7 2010-11-11 11:11:11.000000 2020-03-03 00:00:00.000000 +8 2010-11-11 11:11:11.000000 2020-04-04 00:00:00.000000 +drop table t1; +# +# End of 10.11 tests +# diff --git a/mysql-test/suite/versioning/t/misc.test b/mysql-test/suite/versioning/t/misc.test new file mode 100644 index 00000000000..fd7808687bc --- /dev/null +++ b/mysql-test/suite/versioning/t/misc.test @@ -0,0 +1,21 @@ +# +# simple tests that don't need to be run in multiple various combinations +# +set time_zone='+00:00'; + +--echo # +--echo # MDEV-29721 Inconsistency upon inserting history with visible system versioning columns +--echo # +create table t1 (a int, s timestamp(6) as row start, e timestamp(6) as row end, period for system_time(s,e)) with system versioning; +set system_versioning_insert_history=on; +set timestamp=unix_timestamp('2010-10-10 10:10:10'); +insert t1 (a,s,e) values (1,'2020-01-01',default), (2,'2020-02-02',ignore),(3,default,'2020-03-03'), (4,ignore,'2020-04-04'); +set timestamp=unix_timestamp('2010-11-11 11:11:11'); +insert t1 values (5,'2020-01-01',default), (6,'2020-02-02',ignore),(7,default,'2020-03-03'), (8,ignore,'2020-04-04'); +set timestamp=default; +select * from t1 for system_time all; +drop table t1; + +--echo # +--echo # End of 10.11 tests +--echo # diff --git a/sql/field.cc b/sql/field.cc index c7f63282f0f..4a81ff09a29 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -11307,7 +11307,13 @@ bool Field::save_in_field_default_value(bool view_error_processing) This condition will go away as well as other conditions with vers_sys_field(). */ if (vers_sys_field()) + { + if (flags & VERS_ROW_START) + set_time(); + else + set_max(); return false; + } if (unlikely(flags & NO_DEFAULT_VALUE_FLAG && real_type() != MYSQL_TYPE_ENUM)) diff --git a/sql/table.cc b/sql/table.cc index c85cfa203a2..cf1c6e6b3b6 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -9159,11 +9159,8 @@ bool TABLE::vers_update_fields() bool res= false; if (versioned(VERS_TIMESTAMP) && !vers_start_field()->has_explicit_value()) { - if (vers_start_field()->store_timestamp(in_use->query_start(), - in_use->query_start_sec_part())) - { + if (vers_start_field()->set_time()) DBUG_ASSERT(0); - } } if (!versioned(VERS_TIMESTAMP) || !vers_end_field()->has_explicit_value())