mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
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 mysql-test/r/subselect.result: Aggregate function comparation with ALL/ANY/SOME subselect test mysql-test/t/subselect.test: Aggregate function comparation with ALL/ANY/SOME subselect test sql/item_subselect.cc: removed spaces at lines ends aggregate functions check during substitution made only for single row subselects sql/item_subselect.h: removed spaces at lines ends sql/sql_prepare.cc: restoring current senect pointer before PS rexecution (backport from 5.0)
This commit is contained in:
@ -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;
|
||||
@ -842,7 +842,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
|
||||
{
|
||||
// it is single select without tables => possible optimization
|
||||
item= func->create(left_expr, item);
|
||||
// fix_field of item will be done in time of substituting
|
||||
// fix_field of item will be done in time of substituting
|
||||
substitution= item;
|
||||
have_to_be_excluded= 1;
|
||||
if (thd->lex->describe)
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user