diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 6129850b9dc..449144e3770 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -1246,3 +1246,10 @@ select * from v1; cast(1 as char(3)) 1 drop view v1; +create view v1 as select 'a',1; +create view v2 as select * from v1 union all select * from v1; +create view v3 as select * from v2 where 1 = (select `1` from v2); +create view v4 as select * from v3; +select * from v4; +ERROR 21000: Subquery returns more than 1 row +drop view v4, v3, v2, v1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 3b1d4a0b362..a44624d4df9 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -1196,3 +1196,14 @@ create view v1 as select cast(1 as char(3)); show create view v1; select * from v1; drop view v1; + +# +# bug handlimg from VIEWs +# +create view v1 as select 'a',1; +create view v2 as select * from v1 union all select * from v1; +create view v3 as select * from v2 where 1 = (select `1` from v2); +create view v4 as select * from v3; +-- error 1242 +select * from v4; +drop view v4, v3, v2, v1; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 5ae385ca313..c76a4849776 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1761,9 +1761,9 @@ int open_and_lock_tables(THD *thd, TABLE_LIST *tables) { DBUG_ENTER("open_and_lock_tables"); uint counter; - if (open_tables(thd, tables, &counter) || lock_tables(thd, tables, counter)) + if (open_tables(thd, tables, &counter) || lock_tables(thd, tables, counter) + || mysql_handle_derived(thd->lex)) DBUG_RETURN(thd->net.report_error ? -1 : 1); /* purecov: inspected */ - DBUG_RETURN(mysql_handle_derived(thd->lex)); }