[Commits] 744c1c5: MDEV-9093 Persistent computed column is not updated when update query contains join

OleksandrByelkin sanja at mariadb.com
Mon Dec 14 20:16:29 EET 2015


revision-id: 744c1c5de4dc63fc8291fd69c04a60b395f0fca4 (mariadb-5.5.47-7-g744c1c5)
parent(s): 0ed474484c037a32bea32abaecd3ff770f40bd49
committer: Oleksandr Byelkin
timestamp: 2015-12-14 19:16:29 +0100
message:

MDEV-9093 Persistent computed column is not updated when update query contains join

added lost virtual fields update call

---
 mysql-test/suite/vcol/inc/vcol_ins_upd.inc         | 27 ++++++++++++++++++++++
 mysql-test/suite/vcol/r/vcol_ins_upd_innodb.result | 26 +++++++++++++++++++++
 mysql-test/suite/vcol/r/vcol_ins_upd_myisam.result | 26 +++++++++++++++++++++
 sql/sql_update.cc                                  |  6 +++++
 4 files changed, 85 insertions(+)

diff --git a/mysql-test/suite/vcol/inc/vcol_ins_upd.inc b/mysql-test/suite/vcol/inc/vcol_ins_upd.inc
index 8d0a51f..d9a1e06 100644
--- a/mysql-test/suite/vcol/inc/vcol_ins_upd.inc
+++ b/mysql-test/suite/vcol/inc/vcol_ins_upd.inc
@@ -287,3 +287,30 @@ select * from t1;
 
 set sql_warnings = 0;
 drop table t1;
+
+--echo #
+--echo # MDEV-9093: Persistent computed column is not updated when
+--echo # update query contains join
+--echo #
+
+CREATE TABLE `t1` (
+  `id` bigint(20) NOT NULL,
+  `name` varchar(254) DEFAULT NULL,
+  `name_hash` varchar(64) AS (sha1(name)) PERSISTENT,
+  PRIMARY KEY (`id`)
+);
+
+insert into t1(id,name) values (2050, 'name1'),(2051, 'name2'),(2041, 'name3');
+
+create table t2 (id bigint);
+insert into t2 values (2050),(2051),(2041);
+
+select * from t1;
+
+update t1 join t2 using(id) set name = concat(name,
+'+1') where t1.id in (2051,2041);
+
+select * from t1;
+
+drop table t1,t2;
+
diff --git a/mysql-test/suite/vcol/r/vcol_ins_upd_innodb.result b/mysql-test/suite/vcol/r/vcol_ins_upd_innodb.result
index 44fcae7..af03cc4 100644
--- a/mysql-test/suite/vcol/r/vcol_ins_upd_innodb.result
+++ b/mysql-test/suite/vcol/r/vcol_ins_upd_innodb.result
@@ -425,3 +425,29 @@ select * from t1;
 a	b	c	d
 set sql_warnings = 0;
 drop table t1;
+#
+# MDEV-9093: Persistent computed column is not updated when
+# update query contains join
+#
+CREATE TABLE `t1` (
+`id` bigint(20) NOT NULL,
+`name` varchar(254) DEFAULT NULL,
+`name_hash` varchar(64) AS (sha1(name)) PERSISTENT,
+PRIMARY KEY (`id`)
+);
+insert into t1(id,name) values (2050, 'name1'),(2051, 'name2'),(2041, 'name3');
+create table t2 (id bigint);
+insert into t2 values (2050),(2051),(2041);
+select * from t1;
+id	name	name_hash
+2041	name3	1aefcd1b0f39da45fa1fd7236f683c907c15ef82
+2050	name1	9b46b0dd3a8083c070c3b9953bb5f3f95c5ab4da
+2051	name2	39ea84acf1fef629fef18a9c6f5799bba32ecc25
+update t1 join t2 using(id) set name = concat(name,
+'+1') where t1.id in (2051,2041);
+select * from t1;
+id	name	name_hash
+2041	name3+1	93c9096df48221428de46e146abc9f4f94bf7d2e
+2050	name1	9b46b0dd3a8083c070c3b9953bb5f3f95c5ab4da
+2051	name2+1	fd4f236320db3956a5ec073c5ec39707d7f05708
+drop table t1,t2;
diff --git a/mysql-test/suite/vcol/r/vcol_ins_upd_myisam.result b/mysql-test/suite/vcol/r/vcol_ins_upd_myisam.result
index 6674586..351dfd2 100644
--- a/mysql-test/suite/vcol/r/vcol_ins_upd_myisam.result
+++ b/mysql-test/suite/vcol/r/vcol_ins_upd_myisam.result
@@ -363,3 +363,29 @@ select * from t1;
 a	b	c	d
 set sql_warnings = 0;
 drop table t1;
+#
+# MDEV-9093: Persistent computed column is not updated when
+# update query contains join
+#
+CREATE TABLE `t1` (
+`id` bigint(20) NOT NULL,
+`name` varchar(254) DEFAULT NULL,
+`name_hash` varchar(64) AS (sha1(name)) PERSISTENT,
+PRIMARY KEY (`id`)
+);
+insert into t1(id,name) values (2050, 'name1'),(2051, 'name2'),(2041, 'name3');
+create table t2 (id bigint);
+insert into t2 values (2050),(2051),(2041);
+select * from t1;
+id	name	name_hash
+2050	name1	9b46b0dd3a8083c070c3b9953bb5f3f95c5ab4da
+2051	name2	39ea84acf1fef629fef18a9c6f5799bba32ecc25
+2041	name3	1aefcd1b0f39da45fa1fd7236f683c907c15ef82
+update t1 join t2 using(id) set name = concat(name,
+'+1') where t1.id in (2051,2041);
+select * from t1;
+id	name	name_hash
+2050	name1	9b46b0dd3a8083c070c3b9953bb5f3f95c5ab4da
+2051	name2+1	fd4f236320db3956a5ec073c5ec39707d7f05708
+2041	name3+1	93c9096df48221428de46e146abc9f4f94bf7d2e
+drop table t1,t2;
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index c8a7990..91cb572 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -2234,6 +2234,12 @@ int multi_update::do_updates()
       if (!can_compare_record || compare_record(table))
       {
         int error;
+        if (table->vfield &&
+            update_virtual_fields(thd, table,
+                                  (table->triggers ?
+                                   VCOL_UPDATE_ALL :
+                                   VCOL_UPDATE_FOR_WRITE)))
+          goto err2;
         if ((error= cur_table->view_check_option(thd, ignore)) !=
             VIEW_CHECK_OK)
         {


More information about the commits mailing list