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
1.2048 06/02/13 18:50:06 igor@stripped +3 -0
Fixed bug #16603.
A subquery transformation changes the HAVING clause of the embedding query if the
subquery contains
a GROUP BY clause. Yet the split_sum_func2 function was not applied to the modified
HAVING clause.
This could result in wrong answers.
sql/sql_select.cc
1.394 06/02/13 18:50:00 igor@stripped +15 -14
Fixed bug #16603.
A subquery transformation changes the HAVING clause of the embedding query if the
subquery contains
a GROUP BY clause. Yet the split_sum_func2 function was not applied to the modified
HAVING clause.
This could result in wrong answers.
mysql-test/t/subselect.test
1.113 06/02/13 18:50:00 igor@stripped +22 -0
Added a test case for bug #16603.
mysql-test/r/subselect.result
1.133 06/02/13 18:50:00 igor@stripped +29 -3
Added a test case for bug #16603.
# 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: rurik.mysql.com
# Root: /home/igor/dev/mysql-5.0-0
--- 1.393/sql/sql_select.cc 2006-02-02 23:56:02 -08:00
+++ 1.394/sql/sql_select.cc 2006-02-13 18:50:00 -08:00
@@ -364,22 +364,8 @@
select_lex->having_fix_field= 0;
if (having_fix_rc || thd->net.report_error)
DBUG_RETURN(-1); /* purecov: inspected */
- if (having->with_sum_func)
- having->split_sum_func2(thd, ref_pointer_array, all_fields,
- &having, TRUE);
thd->lex->allow_sum_func= save_allow_sum_func;
}
- if (select_lex->inner_sum_func_list)
- {
- Item_sum *end=select_lex->inner_sum_func_list;
- Item_sum *item_sum= end;
- do
- {
- item_sum= item_sum->next;
- item_sum->split_sum_func2(thd, ref_pointer_array,
- all_fields, item_sum->ref_by, FALSE);
- } while (item_sum != end);
- }
if (!thd->lex->view_prepare_mode)
{
@@ -395,6 +381,21 @@
DBUG_RETURN((res == Item_subselect::RES_ERROR));
}
}
+ }
+
+ if (having && having->with_sum_func)
+ having->split_sum_func2(thd, ref_pointer_array, all_fields,
+ &having, TRUE);
+ if (select_lex->inner_sum_func_list)
+ {
+ Item_sum *end=select_lex->inner_sum_func_list;
+ Item_sum *item_sum= end;
+ do
+ {
+ item_sum= item_sum->next;
+ item_sum->split_sum_func2(thd, ref_pointer_array,
+ all_fields, item_sum->ref_by, FALSE);
+ } while (item_sum != end);
}
if (setup_ftfuncs(select_lex)) /* should be after having->fix_fields */
--- 1.132/mysql-test/r/subselect.result 2006-01-21 06:39:32 -08:00
+++ 1.133/mysql-test/r/subselect.result 2006-02-13 18:50:00 -08:00
@@ -215,9 +215,9 @@
a
select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from
t4;
b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)
-8 7.5
-8 4.5
-9 7.5
+8 7.5000
+8 4.5000
+9 7.5000
explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >=
t4.a)) from t2) from t4;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t4 ALL NULL NULL NULL NULL 3
@@ -3131,3 +3131,29 @@
3 20
4 40
DROP TABLE t1,t2,t3;
+CREATE TABLE t1 (a varchar(5), b varchar(10));
+INSERT INTO t1 VALUES
+('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2),
+('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8);
+SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
+a b
+BBB 4
+CCC 7
+AAA 8
+EXPLAIN
+SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 9 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 9 Using temporary; Using filesort
+ALTER TABLE t1 ADD INDEX(a);
+SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
+a b
+BBB 4
+CCC 7
+AAA 8
+EXPLAIN
+SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 9 Using where
+2 DEPENDENT SUBQUERY t1 index NULL a 8 NULL 9 Using filesort
+DROP TABLE t1;
--- 1.112/mysql-test/t/subselect.test 2005-10-15 14:32:02 -07:00
+++ 1.113/mysql-test/t/subselect.test 2006-02-13 18:50:00 -08:00
@@ -2051,3 +2051,25 @@
HAVING t2.c+sum > 20);
DROP TABLE t1,t2,t3;
+
+#
+# Test for bug #16603: GROUP BY in a row subquery with a quantifier
+# when an index is defined on the grouping field
+
+CREATE TABLE t1 (a varchar(5), b varchar(10));
+INSERT INTO t1 VALUES
+ ('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2),
+ ('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8);
+
+SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
+EXPLAIN
+SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
+
+ALTER TABLE t1 ADD INDEX(a);
+
+SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
+EXPLAIN
+SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
+
+DROP TABLE t1;
+
| Thread |
|---|
| • bk commit into 5.0 tree (igor:1.2048) BUG#16603 | igor | 14 Feb |