summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorevgen@moonbone.local <>2005-07-18 19:37:42 +0400
committerevgen@moonbone.local <>2005-07-18 19:37:42 +0400
commite75e566469d95d2dfdb02067e27fd0993df44341 (patch)
tree8555a1df98205cd318b5558085b136463a640782
parent0fda7038f9e474675d0fd88650e68508f4b09ceb (diff)
parent52569ad519f8357473688f787f435916b889c6fb (diff)
downloadmariadb-git-e75e566469d95d2dfdb02067e27fd0993df44341.tar.gz
Merge moonbone.local:/work/mysql-4.1-bug-11868
into moonbone.local:/work/mysql-5.0-bug-11482
-rw-r--r--mysql-test/r/update.result11
-rw-r--r--mysql-test/t/update.test13
-rw-r--r--sql/sql_select.cc7
3 files changed, 30 insertions, 1 deletions
diff --git a/mysql-test/r/update.result b/mysql-test/r/update.result
index b0055346d61..42fb8064044 100644
--- a/mysql-test/r/update.result
+++ b/mysql-test/r/update.result
@@ -240,3 +240,14 @@ update t1, t2 set t1.a = t2.a where t2.b = t1.b;
show warnings;
Level Code Message
drop table t1, t2;
+create table t1(f1 int, f2 int);
+create table t2(f3 int, f4 int);
+create index idx on t2(f3);
+insert into t1 values(1,0),(2,0);
+insert into t2 values(1,1),(2,2);
+UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
+select * from t1;
+f1 f2
+1 1
+2 2
+drop table t1,t2;
diff --git a/mysql-test/t/update.test b/mysql-test/t/update.test
index 21789a550b9..66b3a2886b6 100644
--- a/mysql-test/t/update.test
+++ b/mysql-test/t/update.test
@@ -201,3 +201,16 @@ analyze table t1,t2;
update t1, t2 set t1.a = t2.a where t2.b = t1.b;
show warnings;
drop table t1, t2;
+
+#
+# Bug #11868 Update with subquery with ref built with a key from the updated
+# table crashes server
+#
+create table t1(f1 int, f2 int);
+create table t2(f3 int, f4 int);
+create index idx on t2(f3);
+insert into t1 values(1,0),(2,0);
+insert into t2 values(1,1),(2,2);
+UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
+select * from t1;
+drop table t1,t2;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index e60688fe574..1e434369a7f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -5185,7 +5185,12 @@ static void add_not_null_conds(JOIN *join)
DBUG_ASSERT(item->type() == Item::FIELD_ITEM);
Item_field *not_null_item= (Item_field*)item;
JOIN_TAB *referred_tab= not_null_item->field->table->reginfo.join_tab;
- if (referred_tab->join != join)
+ /*
+ For UPDATE queries such as:
+ UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
+ not_null_item is the t1.f1, but it's referred_tab is 0.
+ */
+ if (!referred_tab || referred_tab->join != join)
continue;
Item *notnull;
if (!(notnull= new Item_func_isnotnull(not_null_item)))