List:Commits« Previous MessageNext Message »
From:mhansson Date:January 22 2008 4:26pm
Subject:bk commit into 6.0 tree (mhansson:1.2767) BUG#33062
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of martin. When martin does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-01-22 17:26:40+01:00, mhansson@stripped +8 -0
  Bug#33062

  libmysqld/des_key_file.cc@stripped, 2008-01-22 17:26:34+01:00, mhansson@stripped +0 -0
    Bug#33062

  libmysqld/des_key_file.cc@stripped, 2008-01-22 17:26:34+01:00, mhansson@stripped +0 -0

  mysql-test/t/subselect_sj2.test@stripped, 2008-01-22 17:26:34+01:00, mhansson@stripped +30 -0
    Bug#33062

  sql/item.h@stripped, 2008-01-22 17:26:34+01:00, mhansson@stripped +1 -0
    Bug#33062

  sql/item_cmpfunc.cc@stripped, 2008-01-22 17:26:34+01:00, mhansson@stripped +9 -0
    Bug#33062

  sql/item_cmpfunc.h@stripped, 2008-01-22 17:26:34+01:00, mhansson@stripped +1 -0
    Bug#33062

  sql/item_subselect.cc@stripped, 2008-01-22 17:26:34+01:00, mhansson@stripped +6 -1
    Bug#33062

  sql/item_subselect.h@stripped, 2008-01-22 17:26:34+01:00, mhansson@stripped +2 -0
    Bug#33062

  sql/sql_select.cc@stripped, 2008-01-22 17:26:34+01:00, mhansson@stripped +6 -2
    Bug#33062

diff -Nrup a/mysql-test/t/subselect_sj2.test b/mysql-test/t/subselect_sj2.test
--- a/mysql-test/t/subselect_sj2.test	2007-09-26 13:49:29 +02:00
+++ b/mysql-test/t/subselect_sj2.test	2008-01-22 17:26:34 +01:00
@@ -480,3 +480,33 @@ SELECT Name FROM t1 
     SELECT t2.CountryCode FROM t2 WHERE Population > 5000000);
 
 drop table t1, t2;
+
+#
+# Bug#33062: subquery in stored routine cause crash
+#
+
+CREATE TABLE t1(a INT);
+CREATE TABLE t2(c INT);
+
+DELIMITER //;
+
+CREATE PROCEDURE p1(v1 int)
+BEGIN
+  SELECT 1 FROM t1 WHERE a = v1 AND a IN (SELECT c FROM t2);
+END
+//
+
+CREATE PROCEDURE p2(v1 int)
+BEGIN
+  SELECT 1 FROM t1 WHERE a = v1 OR (1 AND a IN (SELECT c FROM t2));
+END
+//
+
+DELIMITER ;//
+
+CALL p1(1);
+CALL p2(1);
+
+DROP TABLE t1, t2;
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
diff -Nrup a/sql/item.h b/sql/item.h
--- a/sql/item.h	2007-12-13 13:56:19 +01:00
+++ b/sql/item.h	2008-01-22 17:26:34 +01:00
@@ -2115,6 +2115,7 @@ public:
     save_in_field(result_field, no_conversions);
   }
   void cleanup();
+  virtual void replace_subcondition(COND **owner, Item *old_cond) {};
 };
 
 
diff -Nrup a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
--- a/sql/item_cmpfunc.cc	2007-12-13 13:56:19 +01:00
+++ b/sql/item_cmpfunc.cc	2008-01-22 17:26:34 +01:00
@@ -4113,6 +4113,15 @@ Item *Item_cond::compile(Item_analyzer a
   return Item_func::transform(transformer, arg_t);
 }
 
+void Item_cond::replace_subcondition(COND **owner, Item *old_cond)
+{
+  List_iterator<Item> li(list);
+  Item *item;
+  while ((item= li++))
+    if (item == old_cond)
+      li.replace(new Item_int(1));
+}
+
 void Item_cond::traverse_cond(Cond_traverser traverser,
                               void *arg, traverse_order order)
 {
diff -Nrup a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
--- a/sql/item_cmpfunc.h	2007-12-13 13:47:14 +01:00
+++ b/sql/item_cmpfunc.h	2008-01-22 17:26:34 +01:00
@@ -1462,6 +1462,7 @@ public:
   bool subst_argument_checker(uchar **arg) { return TRUE; }
   Item *compile(Item_analyzer analyzer, uchar **arg_p,
                 Item_transformer transformer, uchar *arg_t);
+  void replace_subcondition(COND **owner, Item *old_cond);
 };
 
 
diff -Nrup a/sql/item_subselect.cc b/sql/item_subselect.cc
--- a/sql/item_subselect.cc	2007-11-23 12:41:55 +01:00
+++ b/sql/item_subselect.cc	2008-01-22 17:26:34 +01:00
@@ -102,6 +102,11 @@ Item_subselect::get_select_lex()
   return unit->first_select();
 }
 
+void Item_subselect::replace_subcondition(COND **owner, Item *old_cond)
+{
+  *owner= new Item_int(1);
+}
+
 void Item_subselect::cleanup()
 {
   DBUG_ENTER("Item_subselect::cleanup");
@@ -839,6 +844,7 @@ longlong Item_in_subselect::val_int()
     As far as Item_in_subselect called only from Item_in_optimizer this
     method should not be used
   */
+//  return 0;
   DBUG_ASSERT(0);
   DBUG_ASSERT(fixed == 1);
   null_value= 0;
@@ -1883,7 +1889,6 @@ bool Item_in_subselect::is_expensive_pro
 {
   return exec_method == MATERIALIZATION;
 }
-
 
 Item_subselect::trans_res
 Item_allany_subselect::select_transformer(JOIN *join)
diff -Nrup a/sql/item_subselect.h b/sql/item_subselect.h
--- a/sql/item_subselect.h	2007-10-30 15:25:47 +01:00
+++ b/sql/item_subselect.h	2008-01-22 17:26:34 +01:00
@@ -137,6 +137,8 @@ public:
   */
   st_select_lex* get_select_lex();
 
+  void replace_subcondition(COND **owner, Item *old_cond);
+
   friend class select_result_interceptor;
   friend class Item_in_optimizer;
   friend bool Item_field::fix_fields(THD *, Item **);
diff -Nrup a/sql/sql_select.cc b/sql/sql_select.cc
--- a/sql/sql_select.cc	2007-12-13 13:56:21 +01:00
+++ b/sql/sql_select.cc	2008-01-22 17:26:34 +01:00
@@ -3333,14 +3333,18 @@ bool JOIN::flatten_subqueries()
   */
   sj_subselects.sort(subq_sj_candidate_cmp);
   // #tables-in-parent-query + #tables-in-subquery < MAX_TABLES
-  /* Replace all subqueries to be flattened for Item_int(1) */
+  /* Replace all subqueries to be flattened with Item_int(1) */
   arena= thd->activate_stmt_arena_if_needed(&backup);
   for (in_subq= sj_subselects.front(); 
        in_subq != in_subq_end && 
        tables + ((*in_subq)->sj_convert_priority % MAX_TABLES) < MAX_TABLES;
        in_subq++)
   {
-    *((*in_subq)->ref_ptr)= new Item_int(1);
+    if (conds->is_result_field())
+    {
+      Item_result_field *item_result_field= (Item_result_field*)conds;
+      item_result_field->replace_subcondition(&conds, *in_subq);
+    }
   }
  
   for (in_subq= sj_subselects.front(); 
Thread
bk commit into 6.0 tree (mhansson:1.2767) BUG#33062mhansson23 Jan