Commit 13074024 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

aggregate functions check during substitution made only for single row subselects (BUG#4400)

restoring current senect pointer before PS rexecution (backport from 5.0)
removed spaces at  lines ends
parent fb7f1518
......@@ -1891,3 +1891,11 @@ abc b
3 4
deallocate prepare stmt1;
DROP TABLE t1, t2, t3;
CREATE TABLE `t1` ( `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
insert into t1 values (1);
CREATE TABLE `t2` ( `b` int(11) default NULL, `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
insert into t2 values (1,2);
select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1);
a C
1 1
drop table t1,t2;
......@@ -1212,3 +1212,13 @@ execute stmt1;
select * from t3;
deallocate prepare stmt1;
DROP TABLE t1, t2, t3;
#
# Aggregate function comparation with ALL/ANY/SOME subselect
#
CREATE TABLE `t1` ( `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
insert into t1 values (1);
CREATE TABLE `t2` ( `b` int(11) default NULL, `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
insert into t2 values (1,2);
select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1);
drop table t1,t2;
......@@ -151,8 +151,8 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref)
thd->where= "checking transformed subquery";
if (!(*ref)->fixed)
ret= (*ref)->fix_fields(thd, tables, ref);
// We can't substitute aggregate functions (like (SELECT (max(i)))
if ((*ref)->with_sum_func)
// We can't substitute aggregate functions like "SELECT (max(i))"
if (substype() == SINGLEROW_SUBS && (*ref)->with_sum_func)
{
my_error(ER_INVALID_GROUP_FUNC_USE, MYF(0));
return 1;
......
......@@ -1706,6 +1706,7 @@ static void reset_stmt_for_execute(Prepared_statement *stmt)
unit->reinit_exec_mechanism();
}
}
stmt->lex->current_select= &stmt->lex->select_lex;
}
......
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