MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:kgeorge Date:July 26 2006 4:19pm
Subject:bk commit into 4.1 tree (gkodinov:1.2535) BUG#20792
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of kgeorge. When kgeorge 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-26 19:19:30+03:00, gkodinov@stripped +3 -0
  * Bug #20792: Incorrect results from aggregate subquery
  When processing aggregate functions all tables values are reset
  to NULLs at the end of each group. 
  When doing that if there are no rows found for a group
  the const tables must not be reset as they are not recalculated 
  by do_select()/sub_select() for each group.

  mysql-test/r/subselect2.result@stripped, 2006-07-26 19:19:23+03:00, gkodinov@stripped +12 -0
    * Bug #20792: Incorrect results from aggregate subquery
     - test suite for the bug. This is dependent on InnoDB despite
       the fact that the bug and the fix are not InnoDB specific.
       This is because of the table flag HA_NOT_EXACT_COUNT.
       When this flag is off (as in MyISAM) both t2 and t3 become of
       join type 'system' as they are estimated to have 1 record and
       and this statistics can be trusted (according to the absence of
       HA_NOT_EXACT_COUNT).

  mysql-test/t/subselect2.test@stripped, 2006-07-26 19:19:23+03:00, gkodinov@stripped +18 -0
    * Bug #20792: Incorrect results from aggregate subquery
     - test suite for the bug

  sql/sql_select.cc@stripped, 2006-07-26 19:19:24+03:00, gkodinov@stripped +8 -2
    * Bug #20792: Incorrect results from aggregate subquery
     - when clearing results if there are not rows found for group
       the const tables must not be reset as they are not recalculated
       for each group.

# 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:	gkodinov
# Host:	macbook.gmz
# Root:	/Users/kgeorge/mysql/work/B20792-4.1-opt

--- 1.460/sql/sql_select.cc	2006-07-26 19:19:42 +03:00
+++ 1.461/sql/sql_select.cc	2006-07-26 19:19:42 +03:00
@@ -4452,10 +4452,16 @@ return_zero_rows(JOIN *join, select_resu
   DBUG_RETURN(0);
 }
 
-
+/*
+  used only in JOIN::clear
+*/
 static void clear_tables(JOIN *join)
 {
-  for (uint i=0 ; i < join->tables ; i++)
+  /* 
+    must clear only the non-const tables, as const tables
+    are not re-calculated.
+  */
+  for (uint i=join->const_tables ; i < join->tables ; i++)
     mark_as_null_row(join->table[i]);		// All fields are NULL
 }
 

--- 1.8/mysql-test/r/subselect2.result	2006-07-26 19:19:42 +03:00
+++ 1.9/mysql-test/r/subselect2.result	2006-07-26 19:19:42 +03:00
@@ -130,3 +130,15 @@ id	select_type	table	type	possible_keys	
 5	DEPENDENT SUBQUERY	t3	unique_subquery	PRIMARY,FFOLDERID_IDX	PRIMARY	32	func	1	Using index; Using where
 6	DEPENDENT SUBQUERY	t3	unique_subquery	PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX	PRIMARY	32	func	1	Using index; Using where
 drop table t1, t2, t3, t4;
+CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2 (a int(10), PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t2 VALUES (1);
+CREATE TABLE t3 (a int(10), b int(10), c int(10),
+PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t3 VALUES (1,2,1);
+SELECT t1.* FROM t1 WHERE (SELECT COUNT(*) FROM t3,t2 WHERE t3.c=t2.a 
+and t2.a='1' AND t1.a=t3.b) > 0;
+a
+2
+DROP TABLE t1,t2,t3;

--- 1.6/mysql-test/t/subselect2.test	2006-07-26 19:19:42 +03:00
+++ 1.7/mysql-test/t/subselect2.test	2006-07-26 19:19:42 +03:00
@@ -150,3 +150,21 @@ EXPLAIN SELECT t2.*, t4.DOCTYPENAME, t1.
 
 drop table t1, t2, t3, t4;
 # End of 4.1 tests
+
+#
+# Bug #20792: Incorrect results from aggregate subquery
+#
+CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE TABLE t2 (a int(10), PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t2 VALUES (1);
+
+CREATE TABLE t3 (a int(10), b int(10), c int(10),
+                PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t3 VALUES (1,2,1);
+
+SELECT t1.* FROM t1 WHERE (SELECT COUNT(*) FROM t3,t2 WHERE t3.c=t2.a 
+                           and t2.a='1' AND t1.a=t3.b) > 0;
+
+DROP TABLE t1,t2,t3;
Thread
bk commit into 4.1 tree (gkodinov:1.2535) BUG#20792kgeorge26 Jul