From 5b62dfcdf51a695ebc724cb453919eb909ca274f Mon Sep 17 00:00:00 2001
From: unknown <bell@sanja.is.com.ua>
Date: Fri, 29 Nov 2002 10:44:30 +0200
Subject: [PATCH] fixed error handling bug fixed naming bug fixed bug of
 subselect excluding

mysql-test/r/subselect.result:
  test of error handling bug
  test of naming bug
  test bug of subselect excluding
mysql-test/t/subselect.test:
  test of error handling bug
  test of naming bug
  test bug of subselect excluding
sql/item_subselect.cc:
  fixed naming bug
  fixed error handling bug
sql/sql_lex.cc:
  fixed subselect excluding bug
---
 mysql-test/r/subselect.result | 8 ++++++++
 mysql-test/t/subselect.test   | 4 ++++
 sql/item_subselect.cc         | 3 ++-
 sql/sql_lex.cc                | 3 +++
 4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 523c3af91c..bbf70150ee 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -35,6 +35,14 @@ Unknown column 'a' in 'field list'
 SELECT * FROM (SELECT 1 as id) WHERE id IN (SELECT * FROM (SELECT 1 as id) ORDER BY id LIMIT 1);
 id
 1
+SELECT * FROM (SELECT 1) WHERE 1 IN (SELECT 1,1);
+Cardinality error (more/less than 1 columns)
+SELECT 1 IN (SELECT 1);
+1 IN (SELECT 1)
+1
+SELECT 1 FROM (SELECT 1 as a) WHERE 1 IN (SELECT (SELECT a));
+1
+1
 drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
 create table t1 (a int);
 create table t2 (a int, b int);
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index 17f3008b62..c875f8372b 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -16,6 +16,10 @@ SELECT 1 as a FROM (SELECT 1) HAVING (SELECT a)=1;
 -- error 1054
 SELECT 1 FROM (SELECT (SELECT a));
 SELECT * FROM (SELECT 1 as id) WHERE id IN (SELECT * FROM (SELECT 1 as id) ORDER BY id LIMIT 1);
+-- error 1239
+SELECT * FROM (SELECT 1) WHERE 1 IN (SELECT 1,1);
+SELECT 1 IN (SELECT 1);
+SELECT 1 FROM (SELECT 1 as a) WHERE 1 IN (SELECT (SELECT a));
 
 drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
 create table t1 (a int);
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 6d55f7399c..e087664e06 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -92,6 +92,7 @@ bool Item_subselect::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
   if (substitution)
   {
     (*ref)= substitution;
+    substitution->name= name;
     engine->exclude();
     return substitution->fix_fields(thd, tables, ref);
   }
@@ -293,7 +294,7 @@ void Item_in_subselect::single_value_transformer(st_select_lex *select_lex,
     if (sl->item_list.elements > 1)
     {
       my_error(ER_CARDINALITY_COL, MYF(0), 1);
-      item= 0; // Item_asterisk_remover must fail
+      DBUG_VOID_RETURN;
     }
     else
       item= (Item*) sl->item_list.pop();
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index c50321ebed..be0430d4af 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -1071,7 +1071,10 @@ void st_select_lex_unit::exclude_level()
       sl->link_next->link_prev= sl->link_prev;
     SELECT_LEX_UNIT **last= 0;
     for (SELECT_LEX_UNIT *u= sl->first_inner_unit(); u; u= u->next_unit())
+    {
+      u->master= master;
       last= (SELECT_LEX_UNIT**)&(u->next);
+    }
     if (last)
     {
       (*units_last)= sl->first_inner_unit();
-- 
2.30.9