diff --git a/mysql-test/r/cte_nonrecursive.result b/mysql-test/r/cte_nonrecursive.result index a9c13f3f10b..2cc291dcfbc 100644 --- a/mysql-test/r/cte_nonrecursive.result +++ b/mysql-test/r/cte_nonrecursive.result @@ -691,24 +691,27 @@ with recursive t as (select * from s where a>2), s as (select a from t1,r where t1.a>r.c), r as (select c from t,t2 where t.a=t2.c) select * from r where r.c<7; -ERROR HY000: Recursive queries in WITH clause are not supported yet -with t as (select * from s where a>2), +ERROR HY000: No anchors for recursive WITH element 't' +with recursive +t as (select * from s where a>2), s as (select a from t1,r where t1.a>r.c), r as (select c from t,t2 where t.a=t2.c) select * from r where r.c<7; -ERROR HY000: Recursive queries in WITH clause are not supported yet -with t as (select * from t1 +ERROR HY000: No anchors for recursive WITH element 't' +with recursive +t as (select * from t1 where a in (select c from s where b<='ccc') and b>'b'), s as (select * from t1,t2 where t1.a=t2.c and t1.c in (select a from t where a<5)) select * from s where s.b>'aaa'; -ERROR HY000: Recursive queries in WITH clause are not supported yet -with t as (select * from t1 where b>'aaa' and b <='d') +ERROR HY000: No anchors for recursive WITH element 't' +with recursive +t as (select * from t1 where b>'aaa' and b <='d') select t.b from t,t2 where t.a=t2.c and t2.c in (with s as (select t1.a from s,t1 where t1.a=s.a and t1.b<'c') select * from s); -ERROR HY000: Recursive queries in WITH clause are not supported yet +ERROR HY000: No anchors for recursive WITH element 's' #erroneous definition of unreferenced with table t with t as (select count(*) from t1 where d>='f' group by a) select t1.b from t2,t1 where t1.a = t2.c; diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test index e3164f53887..978faaf0a4d 100644 --- a/mysql-test/t/cte_nonrecursive.test +++ b/mysql-test/t/cte_nonrecursive.test @@ -376,27 +376,30 @@ with recursive s as (select a from t1 where b>='d') select * from t,s where t.a=s.a; ---ERROR ER_RECURSIVE_QUERY_IN_WITH_CLAUSE +--ERROR ER_RECURSIVE_WITHOUT_ANCHORS with recursive t as (select * from s where a>2), s as (select a from t1,r where t1.a>r.c), r as (select c from t,t2 where t.a=t2.c) select * from r where r.c<7; ---ERROR ER_RECURSIVE_QUERY_IN_WITH_CLAUSE -with t as (select * from s where a>2), +--ERROR ER_RECURSIVE_WITHOUT_ANCHORS +with recursive + t as (select * from s where a>2), s as (select a from t1,r where t1.a>r.c), r as (select c from t,t2 where t.a=t2.c) select * from r where r.c<7; ---ERROR ER_RECURSIVE_QUERY_IN_WITH_CLAUSE -with t as (select * from t1 +--ERROR ER_RECURSIVE_WITHOUT_ANCHORS +with recursive + t as (select * from t1 where a in (select c from s where b<='ccc') and b>'b'), s as (select * from t1,t2 where t1.a=t2.c and t1.c in (select a from t where a<5)) select * from s where s.b>'aaa'; ---ERROR ER_RECURSIVE_QUERY_IN_WITH_CLAUSE -with t as (select * from t1 where b>'aaa' and b <='d') +--ERROR ER_RECURSIVE_WITHOUT_ANCHORS +with recursive + t as (select * from t1 where b>'aaa' and b <='d') select t.b from t,t2 where t.a=t2.c and t2.c in (with s as (select t1.a from s,t1 where t1.a=s.a and t1.b<'c') diff --git a/mysql-test/t/cte_recursive.test b/mysql-test/t/cte_recursive.test index 34eee6d3bf2..a5ad1d66a51 100644 --- a/mysql-test/t/cte_recursive.test +++ b/mysql-test/t/cte_recursive.test @@ -4,7 +4,7 @@ insert into t1 values insert into t1 values (3,'eee'), (7,'bb'), (1,'fff'), (4,'ggg'); ---ERROR 1984 +--ERROR ER_RECURSIVE_WITHOUT_ANCHORS with recursive a1(a,b) as (select * from t1 where t1.a>3 diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index f2a5666f1b1..38b05ca9dce 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7152,13 +7152,10 @@ ER_DUP_QUERY_NAME eng "Duplicate query name in WITH clause" ER_WRONG_ORDER_IN_WITH_CLAUSE eng "The definition of the table '%s' refers to the table '%s' defined later in a non-recursive WITH clause" -ER_RECURSIVE_QUERY_IN_WITH_CLAUSE - eng "Recursive queries in WITH clause are not supported yet" ER_RECURSIVE_WITHOUT_ANCHORS eng "No anchors for recursive WITH element '%s'" ER_REF_TO_RECURSIVE_WITH_TABLE_IN_DERIVED eng "Reference to recursive WITH table '%s' in materiazed derived" - # # Internal errors, not used # diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 63302c1c6db..95a7ee91435 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -636,6 +636,9 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) bool res= FALSE; DBUG_PRINT("enter", ("unit 0x%lx", (ulong) unit)); + if (!unit) + DBUG_RETURN(FALSE); + SELECT_LEX *first_select= unit->first_select(); if (unit->prepared && derived->is_recursive_with_table() && @@ -665,7 +668,7 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) } // Skip already prepared views/DT - if (!unit || unit->prepared || + if (unit->prepared || (derived->merged_for_insert && !(derived->is_multitable() && (thd->lex->sql_command == SQLCOM_UPDATE_MULTI || diff --git a/sql/sql_union.cc b/sql/sql_union.cc index ac582c115d8..7345c6f224e 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1285,7 +1285,7 @@ bool st_select_lex_unit::cleanup() if (with_element && with_element->is_recursive) with_element->mark_as_cleaned(); - if (union_result && !(with_element->is_recursive)) + if (union_result && !(with_element &&with_element->is_recursive)) { delete union_result; union_result=0; // Safety