Commit cef26176 authored by unknown's avatar unknown

fix of illegal usage aggregate functions


mysql-test/r/subselect.result:
  test of illegal aggregate functions
mysql-test/t/subselect.test:
  test of illegal aggregate functions
parent ab2eeffb
...@@ -1012,3 +1012,13 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -1012,3 +1012,13 @@ id select_type table type possible_keys key key_len ref rows Extra
2 UNCACHEABLE SUBSELECT t1 ALL NULL NULL NULL NULL 3 2 UNCACHEABLE SUBSELECT t1 ALL NULL NULL NULL NULL 3
3 UNCACHEABLE SUBSELECT t1 ALL NULL NULL NULL NULL 3 3 UNCACHEABLE SUBSELECT t1 ALL NULL NULL NULL NULL 3
drop table t1; drop table t1;
CREATE TABLE `t1` (
`i` int(11) NOT NULL default '0',
PRIMARY KEY (`i`)
) TYPE=MyISAM CHARSET=latin1;
INSERT INTO t1 VALUES (1);
UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i));
Invalid use of group function
UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
Invalid use of group function
drop table t1;
...@@ -595,3 +595,15 @@ insert into t1 values (1), (2), (3); ...@@ -595,3 +595,15 @@ insert into t1 values (1), (2), (3);
explain select a,(select (select rand() from t1 limit 1) from t1 limit 1) explain select a,(select (select rand() from t1 limit 1) from t1 limit 1)
from t1; from t1;
drop table t1; drop table t1;
CREATE TABLE `t1` (
`i` int(11) NOT NULL default '0',
PRIMARY KEY (`i`)
) TYPE=MyISAM CHARSET=latin1;
INSERT INTO t1 VALUES (1);
-- error 1111
UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i));
-- error 1111
UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
drop table t1;
...@@ -88,7 +88,14 @@ bool Item_subselect::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) ...@@ -88,7 +88,14 @@ bool Item_subselect::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
if (have_to_be_excluded) if (have_to_be_excluded)
engine->exclude(); engine->exclude();
substitution= 0; substitution= 0;
return (*ref)->fix_fields(thd, tables, ref); int ret= (*ref)->fix_fields(thd, tables, ref);
// We can't substitute aggregate functions (like (SELECT (max(i)))
if ((*ref)->with_sum_func)
{
my_error(ER_INVALID_GROUP_FUNC_USE, MYF(0));
return 1;
}
return ret;
} }
char const *save_where= thd->where; char const *save_where= thd->where;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment