List:Commits« Previous MessageNext Message »
From:Sergey Glukhov Date:February 26 2010 12:16pm
Subject:bzr commit into mysql-pe branch (Sergey.Glukhov:3932)
View as plain text  
#At file:///home/gluh/MySQL/mysql-pe/ based on revid:gshchepa@stripped

 3932 Sergey Glukhov	2010-02-26 [merge]
      5.1-bugteam->mysql-pe merge
     @ mysql-test/r/having.result
        5.1-bugteam->mysql-pe merge
     @ mysql-test/t/having.test
        5.1-bugteam->mysql-pe merge
     @ sql/item_cmpfunc.h
        5.1-bugteam->mysql-pe merge
     @ sql/sql_select.cc
        5.1-bugteam->mysql-pe merge

    modified:
      mysql-test/r/having.result
      mysql-test/t/having.test
      sql/item_cmpfunc.h
      sql/sql_select.cc
=== modified file 'mysql-test/r/having.result'
--- a/mysql-test/r/having.result	2009-10-25 13:41:27 +0000
+++ b/mysql-test/r/having.result	2010-02-26 12:15:31 +0000
@@ -430,6 +430,26 @@ SELECT b, COUNT(DISTINCT a) FROM t1 GROU
 b	COUNT(DISTINCT a)
 NULL	1
 DROP TABLE t1;
+#
+# Bug#50995 Having clause on subquery result produces incorrect results.
+#
+CREATE TABLE t1
+(
+id1 INT,
+id2 INT NOT NULL,
+INDEX id1(id2)
+);
+INSERT INTO t1 SET id1=1, id2=1;
+INSERT INTO t1 SET id1=2, id2=1;
+INSERT INTO t1 SET id1=3, id2=1;
+SELECT t1.id1,
+(SELECT 0 FROM DUAL
+WHERE t1.id1=t1.id1) AS amount FROM t1
+WHERE t1.id2 = 1
+HAVING amount > 0
+ORDER BY t1.id1;
+id1	amount
+DROP TABLE t1;
 End of 5.0 tests
 #
 # BUG#46077 "wrong result: HAVING + ORDER BY + MyISAM + ICP

=== modified file 'mysql-test/t/having.test'
--- a/mysql-test/t/having.test	2009-10-19 20:18:59 +0000
+++ b/mysql-test/t/having.test	2010-02-26 12:15:31 +0000
@@ -442,6 +442,32 @@ INSERT INTO t1 VALUES (1, 1), (2,2), (3,
 SELECT b, COUNT(DISTINCT a) FROM t1 GROUP BY b HAVING b is NULL;
 DROP TABLE t1;
 
+
+--echo #
+--echo # Bug#50995 Having clause on subquery result produces incorrect results.
+--echo #
+
+CREATE TABLE t1
+(
+ id1 INT,
+ id2 INT NOT NULL,
+ INDEX id1(id2)
+);
+
+INSERT INTO t1 SET id1=1, id2=1;
+INSERT INTO t1 SET id1=2, id2=1;
+INSERT INTO t1 SET id1=3, id2=1;
+
+SELECT t1.id1,
+(SELECT 0 FROM DUAL
+ WHERE t1.id1=t1.id1) AS amount FROM t1
+WHERE t1.id2 = 1
+HAVING amount > 0
+ORDER BY t1.id1;
+
+DROP TABLE t1;
+
+
 --echo End of 5.0 tests
 
 --echo #

=== modified file 'sql/item_cmpfunc.h'
--- a/sql/item_cmpfunc.h	2010-02-04 10:55:39 +0000
+++ b/sql/item_cmpfunc.h	2010-02-26 12:15:31 +0000
@@ -1490,9 +1490,21 @@ public:
   Item_cond(THD *thd, Item_cond *item);
   Item_cond(List<Item> &nlist)
     :Item_bool_func(), list(nlist), abort_on_null(0) {}
-  bool add(Item *item) { return list.push_back(item); }
-  bool add_at_head(Item *item) { return list.push_front(item); }
-  void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
+  bool add(Item *item)
+  {
+    DBUG_ASSERT(item);
+    return list.push_back(item);
+  }
+  bool add_at_head(Item *item)
+  {
+    DBUG_ASSERT(item);
+    return list.push_front(item);
+  }
+  void add_at_head(List<Item> *nlist)
+  {
+    DBUG_ASSERT(nlist->elements);
+    list.prepand(nlist);
+  }
   bool fix_fields(THD *, Item **ref);
   void fix_after_pullout(st_select_lex *new_parent, Item **ref);
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-02-25 16:35:28 +0000
+++ b/sql/sql_select.cc	2010-02-26 12:15:31 +0000
@@ -12122,7 +12122,8 @@ Item *eliminate_item_equal(COND *cond, C
   else
   {
     DBUG_ASSERT(cond->type() == Item::COND_ITEM);
-    ((Item_cond *) cond)->add_at_head(&eq_list);
+    if (eq_list.elements)
+      ((Item_cond *) cond)->add_at_head(&eq_list);
   }
 
   cond->quick_fix_field();
@@ -21217,7 +21218,7 @@ static bool add_ref_to_table_cond(THD *t
 
   Item_cond_and *cond=new Item_cond_and();
   TABLE *table=join_tab->table;
-  int error;
+  int error= 0;
   if (!cond)
     DBUG_RETURN(TRUE);
 
@@ -21235,7 +21236,8 @@ static bool add_ref_to_table_cond(THD *t
     cond->fix_fields(thd, (Item**)&cond);
   if (join_tab->select)
   {
-    error=(int) cond->add(join_tab->select->cond);
+    if (join_tab->select->cond)
+      error=(int) cond->add(join_tab->select->cond);
     join_tab->select->cond= cond;
     join_tab->set_select_cond(cond, __LINE__);
   }


Attachment: [text/bzr-bundle] bzr/sergey.glukhov@sun.com-20100226121531-2mcnu35ga7pdutr5.bundle
Thread
bzr commit into mysql-pe branch (Sergey.Glukhov:3932)Sergey Glukhov26 Feb