diff options
author | unknown <bell@sanja.is.com.ua> | 2003-02-15 00:11:00 +0200 |
---|---|---|
committer | unknown <bell@sanja.is.com.ua> | 2003-02-15 00:11:00 +0200 |
commit | cef26176ad3c6224db5b25eb64cd0b301323d288 (patch) | |
tree | d7c517ef1c79abea07b74f64c5c49e4b193ab558 | |
parent | ab2eeffb2443d3c2635c9d26eee73adb148384ad (diff) | |
download | mariadb-git-cef26176ad3c6224db5b25eb64cd0b301323d288.tar.gz |
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
-rw-r--r-- | mysql-test/r/subselect.result | 10 | ||||
-rw-r--r-- | mysql-test/t/subselect.test | 12 | ||||
-rw-r--r-- | sql/item_subselect.cc | 9 |
3 files changed, 30 insertions, 1 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 0d8c96fea85..8cd38ad4385 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -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 3 UNCACHEABLE SUBSELECT t1 ALL NULL NULL NULL NULL 3 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; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 1841e9f109a..85f316deb04 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -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) from 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; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index fb51b5561e9..30643ec8385 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -88,7 +88,14 @@ bool Item_subselect::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) if (have_to_be_excluded) engine->exclude(); 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; |