Loading mysql-test/r/subselect.result +25 −0 Original line number Diff line number Diff line Loading @@ -3880,3 +3880,28 @@ this is a test. 3 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; mysql-test/t/subselect.test +21 −0 Original line number Diff line number Diff line Loading @@ -2741,4 +2741,25 @@ SELECT * FROM (SELECT 'this is ' 'a test.' AS col1, a AS t2 FROM t1) t; 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; sql/item_sum.cc +1 −0 Original line number Diff line number Diff line Loading @@ -269,6 +269,7 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref) 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; } Loading Loading
mysql-test/r/subselect.result +25 −0 Original line number Diff line number Diff line Loading @@ -3880,3 +3880,28 @@ this is a test. 3 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;
mysql-test/t/subselect.test +21 −0 Original line number Diff line number Diff line Loading @@ -2741,4 +2741,25 @@ SELECT * FROM (SELECT 'this is ' 'a test.' AS col1, a AS t2 FROM t1) t; 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;
sql/item_sum.cc +1 −0 Original line number Diff line number Diff line Loading @@ -269,6 +269,7 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref) 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; } Loading