From 37cdb0fbf3d9439829678614443834b2622d82db Mon Sep 17 00:00:00 2001 From: "svoj@may.pils.ru" <> Date: Mon, 19 Jun 2006 14:05:14 +0500 Subject: [PATCH 1/2] BUG#18036 - update of table joined to self reports table as crashed Certain updates of table joined to self results in unexpected behavior. The problem was that record cache was mistakenly enabled for self-joined table updates. Normally record cache must be disabled for such updates. Fixed wrong condition in code that determines whether to use record cache for self-joined table updates. Only MyISAM tables were affected. --- mysql-test/r/myisam.result | 8 ++++++++ mysql-test/t/myisam.test | 9 +++++++++ sql/sql_update.cc | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index 3b4519e5444..7aaf3c8f85a 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -748,3 +748,11 @@ select count(id1) from t1 where id2 = 10; count(id1) 5 drop table t1; +CREATE TABLE t1(a CHAR(9), b VARCHAR(7)) ENGINE=MyISAM; +INSERT INTO t1(a) VALUES('xxxxxxxxx'),('xxxxxxxxx'); +UPDATE t1 AS ta1,t1 AS ta2 SET ta1.b='aaaaaa',ta2.b='bbbbbb'; +SELECT * FROM t1; +a b +xxxxxxxxx bbbbbb +xxxxxxxxx bbbbbb +DROP TABLE t1; diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test index 7e4cc324b12..5f948973141 100644 --- a/mysql-test/t/myisam.test +++ b/mysql-test/t/myisam.test @@ -705,4 +705,13 @@ select count(*) from t1 where id2 = 10; select count(id1) from t1 where id2 = 10; drop table t1; +# +# BUG#18036 - update of table joined to self reports table as crashed +# +CREATE TABLE t1(a CHAR(9), b VARCHAR(7)) ENGINE=MyISAM; +INSERT INTO t1(a) VALUES('xxxxxxxxx'),('xxxxxxxxx'); +UPDATE t1 AS ta1,t1 AS ta2 SET ta1.b='aaaaaa',ta2.b='bbbbbb'; +SELECT * FROM t1; +DROP TABLE t1; + # End of 4.1 tests diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 48a8cf93917..16423b39786 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -862,7 +862,7 @@ int multi_update::prepare(List ¬_used_values, for (table_ref= all_tables; table_ref; table_ref=table_ref->next) { TABLE *table=table_ref->table; - if (!(tables_to_update & table->map) && + if ((tables_to_update & table->map) && mysql_lock_have_duplicate(thd, table, update_tables)) table->no_cache= 1; // Disable row cache } From 2c28b3cbf1383d46c31e42dffed6458082a4b3e5 Mon Sep 17 00:00:00 2001 From: "svoj@may.pils.ru" <> Date: Mon, 19 Jun 2006 17:50:52 +0500 Subject: [PATCH 2/2] Addition to fix for BUG#18036 - update of table joined to self reports table as crashed Set exclude_from_table_unique_test value back to FALSE. It is needed for further check in multi_update::prepare whether to use record cache. --- sql/sql_update.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 9c5e98f4424..c2b7624c9e7 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -859,7 +859,12 @@ reopen_tables: } } } - + /* + Set exclude_from_table_unique_test value back to FALSE. It is needed for + further check in multi_update::prepare whether to use record cache. + */ + lex->select_lex.exclude_from_table_unique_test= FALSE; + if (thd->fill_derived_tables() && mysql_handle_derived(lex, &mysql_derived_filling)) DBUG_RETURN(TRUE);