From c5a83411157e764a599ec69544bf085d435dd84f Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Thu, 20 Jul 2023 14:13:59 +0300 Subject: [PATCH] MDEV-23100 ODKU of non-versioning column inserts history row Use vers_check_update() to avoid inserting history row for ODKU if now versioned fields specified in update_fields. --- mysql-test/suite/versioning/r/update.result | 14 ++++++++++++++ mysql-test/suite/versioning/t/update.test | 16 ++++++++++++++++ sql/sql_insert.cc | 3 ++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/versioning/r/update.result b/mysql-test/suite/versioning/r/update.result index cbb75a10cf5..f0a5052acf9 100644 --- a/mysql-test/suite/versioning/r/update.result +++ b/mysql-test/suite/versioning/r/update.result @@ -437,4 +437,18 @@ update t1 set a = 3 where b <= 9; update t2 set a = 3 where b <= 9; update t1, t2 set t1.a = 3, t2.a = 3 where t1.b <= 10 and t2.b <= 10 and t1.b = t2.b; drop tables t1, t2; +# +# MDEV-23100 ODKU of non-versioning column inserts history row +# +create table t1 ( +x int unique, +y int without system versioning +) with system versioning; +insert into t1 (x, y) values ('1', '1'); +insert into t1 (x, y) values ('1', '2') +on duplicate key update y = 3; +select x, y, check_row_ts(row_start, row_end) from t1 for system_time all order by row_end; +x y check_row_ts(row_start, row_end) +1 3 CURRENT ROW +drop table t1; # End of 10.4 tests diff --git a/mysql-test/suite/versioning/t/update.test b/mysql-test/suite/versioning/t/update.test index 56bbd909256..b86296616fd 100644 --- a/mysql-test/suite/versioning/t/update.test +++ b/mysql-test/suite/versioning/t/update.test @@ -373,6 +373,22 @@ update t1, t2 set t1.a = 3, t2.a = 3 where t1.b <= 10 and t2.b <= 10 and t1.b = # cleanup drop tables t1, t2; +--echo # +--echo # MDEV-23100 ODKU of non-versioning column inserts history row +--echo # +create table t1 ( + x int unique, + y int without system versioning +) with system versioning; + +insert into t1 (x, y) values ('1', '1'); +insert into t1 (x, y) values ('1', '2') + on duplicate key update y = 3; + +select x, y, check_row_ts(row_start, row_end) from t1 for system_time all order by row_end; + +drop table t1; + --echo # End of 10.4 tests source suite/versioning/common_finish.inc; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 0f1b66f7610..a2c571373cb 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1916,7 +1916,8 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) if (error != HA_ERR_RECORD_IS_THE_SAME) { info->updated++; - if (table->versioned()) + if (table->versioned() && + table->vers_check_update(*info->update_fields)) { if (table->versioned(VERS_TIMESTAMP)) {