From ae729f93158e57ef52b57ead0ec4f0c052fdda92 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 26 Nov 2002 16:49:55 +0200 Subject: [PATCH] A fix for a bug with derived tables within subselect within derived tables within ...... --- mysql-test/r/derived.result | 3 +++ mysql-test/t/derived.test | 3 ++- sql/sql_derived.cc | 18 +++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result index 204ca86f306..b397c2f7635 100644 --- a/mysql-test/r/derived.result +++ b/mysql-test/r/derived.result @@ -65,3 +65,6 @@ a t 19 19 20 20 drop table if exists t1; +SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a))); +(SELECT * FROM (SELECT 1 as a)) +1 diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test index de765a0e280..c1d8af4074a 100644 --- a/mysql-test/t/derived.test +++ b/mysql-test/t/derived.test @@ -33,4 +33,5 @@ while ($1) } enable_query_log; SELECT * FROM (SELECT * FROM t1) ORDER BY a ASC LIMIT 0,20; -drop table if exists t1; \ No newline at end of file +drop table if exists t1; +SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a))); diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index b3d2b1602d0..6dc001a1932 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -50,15 +50,19 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t) if (res) DBUG_RETURN(-1); - for (TABLE_LIST *cursor= (TABLE_LIST *)tables; - cursor; - cursor=cursor->next) + for (SELECT_LEX *ssl= sl; ssl; ssl= ssl->next_select_in_list()) { - if (cursor->derived) + TABLE_LIST *t_tables= (TABLE_LIST *)ssl->table_list.first; + for (TABLE_LIST *cursor= (TABLE_LIST *)t_tables; + cursor; + cursor=cursor->next) { - res= mysql_derived(thd, lex, (SELECT_LEX_UNIT *)cursor->derived, - cursor); - if (res) DBUG_RETURN(res); + if (cursor->derived) + { + res= mysql_derived(thd, lex, (SELECT_LEX_UNIT *)cursor->derived, + cursor); + if (res) DBUG_RETURN(res); + } } } Item *item;