Below is the list of changes that have just been committed into a local
5.0 repository of igor. When igor 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, 2007-03-20 11:51:09-07:00, igor@stripped +3 -0
Fixed bug #27257: queries containing subqueries with COUNT(*)
aggregated in outer context returned wrong results.
This happened only if the subquery did not contain any references
to outer fields.
As there were no references to outer fields the subquery erroneously
was taken for non-correlated one.
Now any set function aggregated in outer context makes the subquery
correlated.
mysql-test/r/subselect.result@stripped, 2007-03-20 11:51:06-07:00, igor@stripped +25
-0
Added a test case for bug #27257.
mysql-test/t/subselect.test@stripped, 2007-03-20 11:51:07-07:00, igor@stripped +21 -0
Added a test case for bug #27257.
sql/item_sum.cc@stripped, 2007-03-20 11:51:07-07:00, igor@stripped +1 -0
Fixed bug #27257: queries containing subqueries with COUNT(*)
aggregated in outer context returned wrong results.
This happened only if the subquery did not contain any references
to outer fields.
As there were no references to outer fields the subquery erroneously
was taken for non-correlated one.
Now any set function aggregated in outer context makes the subquery
correlated.
# 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: igor
# Host: olga.mysql.com
# Root: /home/igor/dev-opt/mysql-5.0-opt-bug27257
--- 1.196/sql/item_sum.cc 2007-03-20 11:51:14 -07:00
+++ 1.197/sql/item_sum.cc 2007-03-20 11:51:14 -07:00
@@ -267,6 +267,7 @@
sl= sl->master_unit()->outer_select() )
sl->master_unit()->item->with_sum_func= 1;
}
+ thd->lex->current_select->mark_as_dependent(aggr_sl);
return FALSE;
}
--- 1.179/mysql-test/r/subselect.result 2007-03-20 11:51:14 -07:00
+++ 1.180/mysql-test/r/subselect.result 2007-03-20 11:51:14 -07:00
@@ -3880,3 +3880,28 @@
this is a test. 1
this is a test. 2
DROP table t1;
+CREATE TABLE t1 (a int, b int);
+CREATE TABLE t2 (m int, n int);
+INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
+INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
+SELECT COUNT(*), a,
+(SELECT m FROM t2 WHERE m = count(*) LIMIT 1)
+FROM t1 GROUP BY a;
+COUNT(*) a (SELECT m FROM t2 WHERE m = count(*) LIMIT 1)
+2 2 2
+3 3 3
+1 4 1
+SELECT COUNT(*), a,
+(SELECT MIN(m) FROM t2 WHERE m = count(*))
+FROM t1 GROUP BY a;
+COUNT(*) a (SELECT MIN(m) FROM t2 WHERE m = count(*))
+2 2 2
+3 3 3
+1 4 1
+SELECT COUNT(*), a
+FROM t1 GROUP BY a
+HAVING (SELECT MIN(m) FROM t2 WHERE m = count(*)) > 1;
+COUNT(*) a
+2 2
+3 3
+DROP TABLE t1,t2;
--- 1.144/mysql-test/t/subselect.test 2007-03-20 11:51:14 -07:00
+++ 1.145/mysql-test/t/subselect.test 2007-03-20 11:51:14 -07:00
@@ -2741,4 +2741,25 @@
DROP table t1;
+#
+# Bug #27257: COUNT(*) aggregated in outer query
+#
+CREATE TABLE t1 (a int, b int);
+CREATE TABLE t2 (m int, n int);
+INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
+INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
+
+SELECT COUNT(*), a,
+ (SELECT m FROM t2 WHERE m = count(*) LIMIT 1)
+ FROM t1 GROUP BY a;
+
+SELECT COUNT(*), a,
+ (SELECT MIN(m) FROM t2 WHERE m = count(*))
+ FROM t1 GROUP BY a;
+
+SELECT COUNT(*), a
+ FROM t1 GROUP BY a
+ HAVING (SELECT MIN(m) FROM t2 WHERE m = count(*)) > 1;
+
+DROP TABLE t1,t2;
| Thread |
|---|
| • bk commit into 5.0 tree (igor:1.2487) BUG#27257 | igor | 20 Mar |