summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/derived.result27
-rw-r--r--mysql-test/t/derived.test34
-rw-r--r--sql/sql_derived.cc3
-rw-r--r--sql/sql_prepare.cc8
4 files changed, 70 insertions, 2 deletions
diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result
index 1042ee79e8c..e68636e0394 100644
--- a/mysql-test/r/derived.result
+++ b/mysql-test/r/derived.result
@@ -438,5 +438,32 @@ CALL p();
id
drop procedure p;
drop temporary table t1;
+#
+# MDEV-5143: update of a joined table with a nested subquery with
+# a syntax error crashes mysqld with signal 11
+#
+create table t1 (id int(11) not null auto_increment, val varchar(100) null,primary key (id));
+create table t2 (id int(11) not null auto_increment, val varchar(100) null,primary key (id));
+insert into t1 (val) values('a');
+insert into t2 (val) values('1');
+update
+(
+select
+val
+from
+(
+select
+v.val
+from
+t2 wrong_table_alias
+) t4
+) t3
+inner join t1 on
+t1.id=t3.val
+set
+t1.val=t3.val
+;
+ERROR 42S22: Unknown column 'v.val' in 'field list'
+drop table t1, t2;
# End of 5.3 tests
set optimizer_switch=@save_derived_optimizer_switch;
diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test
index b0db0e8100a..2a5ba77f38e 100644
--- a/mysql-test/t/derived.test
+++ b/mysql-test/t/derived.test
@@ -350,6 +350,40 @@ drop procedure p;
drop temporary table t1;
+
+--echo #
+--echo # MDEV-5143: update of a joined table with a nested subquery with
+--echo # a syntax error crashes mysqld with signal 11
+--echo #
+
+create table t1 (id int(11) not null auto_increment, val varchar(100) null,primary key (id));
+create table t2 (id int(11) not null auto_increment, val varchar(100) null,primary key (id));
+
+insert into t1 (val) values('a');
+insert into t2 (val) values('1');
+
+--error ER_BAD_FIELD_ERROR
+update
+ (
+ select
+ val
+ from
+ (
+ select
+ v.val
+ from
+ t2 wrong_table_alias
+ ) t4
+ ) t3
+ inner join t1 on
+ t1.id=t3.val
+set
+ t1.val=t3.val
+;
+
+drop table t1, t2;
+
+
--echo # End of 5.3 tests
set optimizer_switch=@save_derived_optimizer_switch;
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
index db6ab1fb269..9d04beaf73e 100644
--- a/sql/sql_derived.cc
+++ b/sql/sql_derived.cc
@@ -619,7 +619,8 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
{
sl->context.outer_context= 0;
// Prepare underlying views/DT first.
- sl->handle_derived(lex, DT_PREPARE);
+ if ((res= sl->handle_derived(lex, DT_PREPARE)))
+ goto exit;
if (derived->outer_join)
{
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 552b2145540..b4160991493 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -2485,7 +2485,13 @@ void reinit_stmt_before_use(THD *thd, LEX *lex)
/* Fix ORDER list */
for (order= sl->order_list.first; order; order= order->next)
order->item= &order->item_ptr;
- sl->handle_derived(lex, DT_REINIT);
+ {
+#ifndef DBUG_OFF
+ bool res=
+#endif
+ sl->handle_derived(lex, DT_REINIT);
+ DBUG_ASSERT(res == 0);
+ }
}
{
SELECT_LEX_UNIT *unit= sl->master_unit();