MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Sergey Petrunia Date:July 20 2006 7:00pm
Subject:bk commit into 4.1 tree (sergefp:1.2524) BUG#20975
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of psergey. When psergey 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, 2006-07-20 23:00:44+04:00, sergefp@stripped +8 -0
  BUG#20975: Incorrect query result for NOT (subquery):
   Add implementations of Item_func_no{p,t}_all::neg_transformer

  mysql-test/r/subselect.result@stripped, 2006-07-20 23:00:40+04:00, sergefp@stripped +26 -0
    BUG#20975: testcase

  mysql-test/t/subselect.test@stripped, 2006-07-20 23:00:40+04:00, sergefp@stripped +16 -0
    BUG#20975: testcase

  sql/item_cmpfunc.cc@stripped, 2006-07-20 23:00:40+04:00, sergefp@stripped +22 -0
    BUG#20975: Incorrect query result for NOT (subquery):
      Add implementations of Item_func_no{p,t}_all::neg_transformer

  sql/item_cmpfunc.h@stripped, 2006-07-20 23:00:40+04:00, sergefp@stripped +2 -0
    BUG#20975: Incorrect query result for NOT (subquery):
     Add implementations of Item_func_no{p,t}_all::neg_transformer

  sql/item_subselect.cc@stripped, 2006-07-20 23:00:40+04:00, sergefp@stripped +3 -3
    BUG#20975: Incorrect query result for NOT (subquery):
     Add implementations of Item_func_no{p,t}_all::neg_transformer

  sql/item_subselect.h@stripped, 2006-07-20 23:00:40+04:00, sergefp@stripped +4 -5
    BUG#20975: Incorrect query result for NOT (subquery):
     Add implementations of Item_func_no{p,t}_all::neg_transformer

  sql/mysql_priv.h@stripped, 2006-07-20 23:00:40+04:00, sergefp@stripped +2 -1
    Make chooser_compare_func_creator visible in item.h

  sql/sql_parse.cc@stripped, 2006-07-20 23:00:40+04:00, sergefp@stripped +1 -1
    BUG#20975: Incorrect query result for NOT (subquery):
     Add implementations of Item_func_no{p,t}_all::neg_transformer

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	sergefp
# Host:	newbox.mylan
# Root:	/home/psergey/mysql-4.1-bug20975

--- 1.212/sql/item_cmpfunc.cc	2006-07-20 23:00:48 +04:00
+++ 1.213/sql/item_cmpfunc.cc	2006-07-20 23:00:48 +04:00
@@ -3099,6 +3099,28 @@
 }
 
 
+Item *Item_func_nop_all::neg_transformer(THD *thd)
+{
+  /* "NOT (e $cmp$ ANY (SELECT ...)) -> e $rev_cmp$" ALL (SELECT ...) */
+  Item_func_not_all *new_item= new Item_func_not_all(args[0]);
+  Item_allany_subselect *allany= (Item_allany_subselect*)args[0];
+  allany->func= allany->func_creator(FALSE);
+  allany->all= !allany->all;
+  allany->upper_item= new_item;
+  return new_item;
+}
+
+Item *Item_func_not_all::neg_transformer(THD *thd)
+{
+  /* "NOT (e $cmp$ ALL (SELECT ...)) -> e $rev_cmp$" ANY (SELECT ...) */
+  Item_func_nop_all *new_item= new Item_func_nop_all(args[0]);
+  Item_allany_subselect *allany= (Item_allany_subselect*)args[0];
+  allany->all= !allany->all;
+  allany->func= allany->func_creator(TRUE);
+  allany->upper_item= new_item;
+  return new_item;
+}
+
 Item *Item_func_eq::negated_item()		/* a = b  ->  a != b */
 {
   return new Item_func_ne(args[0], args[1]);

--- 1.116/sql/item_cmpfunc.h	2006-07-20 23:00:48 +04:00
+++ 1.117/sql/item_cmpfunc.h	2006-07-20 23:00:48 +04:00
@@ -268,6 +268,7 @@
   void set_sum_test(Item_sum_hybrid *item) { test_sum_item= item; };
   void set_sub_test(Item_maxmin_subselect *item) { test_sub_item= item; };
   bool empty_underlying_subquery();
+  Item *neg_transformer(THD *thd);
 };
 
 
@@ -278,6 +279,7 @@
   Item_func_nop_all(Item *a) :Item_func_not_all(a) {}
   longlong val_int();
   const char *func_name() const { return "<nop>"; }
+  Item *neg_transformer(THD *thd);
 };
 
 

--- 1.379/sql/mysql_priv.h	2006-07-20 23:00:48 +04:00
+++ 1.380/sql/mysql_priv.h	2006-07-20 23:00:48 +04:00
@@ -387,8 +387,9 @@
   OPT_DEFAULT, OPT_SESSION, OPT_GLOBAL
 };
 class sys_var;
-#include "item.h"
+class Comp_creator;
 typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
+#include "item.h"
 /* sql_parse.cc */
 void free_items(Item *item);
 void cleanup_items(Item *item);

--- 1.484/sql/sql_parse.cc	2006-07-20 23:00:48 +04:00
+++ 1.485/sql/sql_parse.cc	2006-07-20 23:00:48 +04:00
@@ -5442,7 +5442,7 @@
     return new Item_func_not(new Item_in_subselect(left_expr, select_lex));
 
   Item_allany_subselect *it=
-    new Item_allany_subselect(left_expr, (*cmp)(all), select_lex, all);
+    new Item_allany_subselect(left_expr, cmp, select_lex, all);
   if (all)
     return it->upper_item= new Item_func_not_all(it);	/* ALL */
 

--- 1.177/mysql-test/r/subselect.result	2006-07-20 23:00:48 +04:00
+++ 1.178/mysql-test/r/subselect.result	2006-07-20 23:00:48 +04:00
@@ -2868,3 +2868,29 @@
 select 1 from dual where 1 < all (select 2 from dual where 1!=1);
 1
 1
+create table t1 (s1 char);
+insert into t1 values (1),(2);
+select * from t1 where (s1 < any (select s1 from t1));
+s1
+1
+select * from t1 where not (s1 < any (select s1 from t1));
+s1
+2
+select * from t1 where (s1 < ALL (select s1+1 from t1));
+s1
+1
+select * from t1 where not(s1 < ALL (select s1+1 from t1));
+s1
+2
+select * from t1 where (s1+1 = ANY (select s1 from t1));
+s1
+1
+select * from t1 where NOT(s1+1 = ANY (select s1 from t1));
+s1
+2
+select * from t1 where (s1 = ALL (select s1/s1 from t1));
+s1
+1
+select * from t1 where NOT(s1 = ALL (select s1/s1 from t1));
+s1
+2

--- 1.155/mysql-test/t/subselect.test	2006-07-20 23:00:48 +04:00
+++ 1.156/mysql-test/t/subselect.test	2006-07-20 23:00:48 +04:00
@@ -1844,4 +1844,20 @@
 select 1 from dual where 2 > all (select 1);
 select 1 from dual where 1 < any (select 2 from dual);
 select 1 from dual where 1 < all (select 2 from dual where 1!=1);
+
+# BUG#20975 Wrong query results for subqueries within NOT
+create table t1 (s1 char);
+insert into t1 values (1),(2);
+
+select * from t1 where (s1 < any (select s1 from t1));
+select * from t1 where not (s1 < any (select s1 from t1));
+
+select * from t1 where (s1 < ALL (select s1+1 from t1));
+select * from t1 where not(s1 < ALL (select s1+1 from t1));
+
+select * from t1 where (s1+1 = ANY (select s1 from t1));
+select * from t1 where NOT(s1+1 = ANY (select s1 from t1));
+
+select * from t1 where (s1 = ALL (select s1/s1 from t1));
+select * from t1 where NOT(s1 = ALL (select s1/s1 from t1));
 # End of 4.1 tests

--- 1.141/sql/item_subselect.cc	2006-07-20 23:00:48 +04:00
+++ 1.142/sql/item_subselect.cc	2006-07-20 23:00:48 +04:00
@@ -542,14 +542,14 @@
 }
 
 Item_allany_subselect::Item_allany_subselect(Item * left_exp,
-					     Comp_creator *fn,
+                                             chooser_compare_func_creator fc,
 					     st_select_lex *select_lex,
 					     bool all_arg)
-  :Item_in_subselect(), all(all_arg)
+  :Item_in_subselect(), all(all_arg), func_creator(fc)
 {
   DBUG_ENTER("Item_in_subselect::Item_in_subselect");
   left_expr= left_exp;
-  func= fn;
+  func= func_creator(all_arg);
   init(select_lex, new select_exists_subselect(this));
   max_columns= 1;
   abort_on_null= 0;

--- 1.62/sql/item_subselect.h	2006-07-20 23:00:48 +04:00
+++ 1.63/sql/item_subselect.h	2006-07-20 23:00:48 +04:00
@@ -251,14 +251,13 @@
 /* ALL/ANY/SOME subselect */
 class Item_allany_subselect :public Item_in_subselect
 {
-protected:
-  Comp_creator *func;
-
 public:
+  chooser_compare_func_creator func_creator;
+  Comp_creator *func;
   bool all;
 
-  Item_allany_subselect(Item * left_expr, Comp_creator *f,
-		     st_select_lex *select_lex, bool all);
+  Item_allany_subselect(Item * left_expr, chooser_compare_func_creator fc,
+                        st_select_lex *select_lex, bool all);
 
   // only ALL subquery has upper not
   subs_type substype() { return all?ALL_SUBS:ANY_SUBS; }
Thread
bk commit into 4.1 tree (sergefp:1.2524) BUG#20975Sergey Petrunia20 Jul