MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:eugene Date:July 8 2006 12:12am
Subject:bk commit into 4.1 tree (evgen:1.2516) BUG#18503
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of evgen. When evgen 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-08 04:12:06+04:00, evgen@stripped +3 -0
  Fixed bug#18503: Queries with a subquery returning empty set may return wrong
  result.
  
  The Item_sum_hybrid have the was_values flag which indicates whether any values
  were added to the sum function. By default it is set to true and reset to false
  on no_rows_in_result() call. This method is called only in return_zero_rows()
  function. An ALL/ANY subquery can be optimized by MIN/MAX optimization and in
  this case the was_values flag is used to detect that subquery returns no rows.
  This bug occurs because return_zero_rows() is called only when we know that the 
  select will return zero rows before starting any scans but InnoDB can't provide
  such information. Due to was_values flag wasn't reset to false the 
  Item_func_not_all and Item_func_nop_all functions returns wrong comparison
  result.
  
  The end_send_group() function now calls no_rows_in_result() for each item
  in the fields_list if there is no matching rows were found.

  mysql-test/r/subselect.result@stripped, 2006-07-08 04:09:19+04:00, evgen@stripped +20 -0
    Added test case for bug#18503: Queries with a subquery returning empty set may return wrong result.
    

  mysql-test/t/subselect.test@stripped, 2006-07-08 04:09:11+04:00, evgen@stripped +16 -0
    Added test case for bug#18503: Queries with a subquery returning empty set may return wrong result.

  sql/sql_select.cc@stripped, 2006-07-08 04:09:31+04:00, evgen@stripped +5 -0
    Fixed bug#18503: Queries with a subquery returning empty set may return wrong result.
    
    The end_send_group() function now calls no_rows_in_result() for each item
    in the fields_list if there is no matching rows were found.

# 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:	evgen
# Host:	moonbone.local
# Root:	/work/18503-bug-4.1-mysql

--- 1.456/sql/sql_select.cc	2006-07-08 04:12:09 +04:00
+++ 1.457/sql/sql_select.cc	2006-07-08 04:12:09 +04:00
@@ -6746,8 +6746,13 @@
 	{
 	  if (!join->first_record)
 	  {
+            List_iterator_fast<Item> it(*join->fields);
+            Item *item;
 	    /* No matching rows for group function */
 	    join->clear();
+
+            while ((item= it++))
+              item->no_rows_in_result();
 	  }
 	  if (join->having && join->having->val_int() == 0)
 	    error= -1;				// Didn't satisfy having

--- 1.175/mysql-test/r/subselect.result	2006-07-08 04:12:09 +04:00
+++ 1.176/mysql-test/r/subselect.result	2006-07-08 04:12:09 +04:00
@@ -2835,3 +2835,23 @@
 4
 DROP TABLE t1,t2,t3;
 purge master logs before (select adddate(current_timestamp(), interval -4 day));
+CREATE TABLE t1 (f1 INT) engine='InnoDB';
+CREATE TABLE t2 (f2 INT) engine='InnoDB';
+INSERT INTO t1 VALUES (1);
+SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2);
+f1
+1
+SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE 1=0);
+f1
+1
+INSERT INTO t2 VALUES (1);
+SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE f2=0);
+f1
+1
+DROP TABLE t2;
+CREATE TABLE t2 (f2 INT);
+INSERT INTO t2 VALUES (1);
+INSERT INTO t2 VALUES (1);
+SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE f2=0);
+f1
+1

--- 1.153/mysql-test/t/subselect.test	2006-07-08 04:12:09 +04:00
+++ 1.154/mysql-test/t/subselect.test	2006-07-08 04:12:09 +04:00
@@ -1820,4 +1820,20 @@
 
 purge master logs before (select adddate(current_timestamp(), interval -4 day));
 
+
+#
+# Bug#18503: Queries with subquery returning empty set may return wrong result. 
+#
+CREATE TABLE t1 (f1 INT) engine='InnoDB';
+CREATE TABLE t2 (f2 INT) engine='InnoDB';
+INSERT INTO t1 VALUES (1);
+SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2);
+SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE 1=0);
+INSERT INTO t2 VALUES (1);
+SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE f2=0);
+DROP TABLE t2;
+CREATE TABLE t2 (f2 INT);
+INSERT INTO t2 VALUES (1);
+INSERT INTO t2 VALUES (1);
+SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE f2=0);
 # End of 4.1 tests
Thread
bk commit into 4.1 tree (evgen:1.2516) BUG#18503eugene8 Jul