mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
after review fixes:
allowed parsing of table fields inside aggregate functions added new tests of fields resolving in grouping
This commit is contained in:
@ -285,6 +285,15 @@ insert into t2 values (1, 5), (2, 4), (3, 3), (3,3);
|
||||
select group_concat(c) from t1;
|
||||
group_concat(c)
|
||||
2,3,4,5
|
||||
select group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1;
|
||||
grp
|
||||
5,4,3,2
|
||||
select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1;
|
||||
grp
|
||||
5,4,3,2
|
||||
select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1;
|
||||
grp
|
||||
2,4,3,5
|
||||
select t1.a, group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1 group by 1;
|
||||
a grp
|
||||
1 2
|
||||
|
@ -1954,4 +1954,12 @@ howmanyvalues mycount
|
||||
2 2
|
||||
3 3
|
||||
4 4
|
||||
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
|
||||
howmanyvalues mycount
|
||||
1 1
|
||||
2 2
|
||||
3 3
|
||||
4 4
|
||||
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues;
|
||||
ERROR 42S22: Unknown column 'a.avalue' in 'where clause'
|
||||
drop table t1;
|
||||
|
@ -168,8 +168,10 @@ insert into t1 values (1, 2), (2, 3), (2, 4), (3, 5);
|
||||
create table t2 (a int, c int);
|
||||
insert into t2 values (1, 5), (2, 4), (3, 3), (3,3);
|
||||
select group_concat(c) from t1;
|
||||
select group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1;
|
||||
select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1;
|
||||
select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1;
|
||||
select t1.a, group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1 group by 1;
|
||||
|
||||
select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1 group by 1;
|
||||
select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1 group by 1;
|
||||
|
||||
|
@ -1259,4 +1259,7 @@ SELECT howmanyvalues, count(*) from t1 group by howmanyvalues;
|
||||
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
|
||||
CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues);
|
||||
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues;
|
||||
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
|
||||
-- error 1054
|
||||
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues;
|
||||
drop table t1;
|
||||
|
@ -70,7 +70,14 @@ void Item_subselect::init(st_select_lex *select_lex,
|
||||
}
|
||||
else
|
||||
{
|
||||
parsing_place= unit->outer_select()->parsing_place;
|
||||
SELECT_LEX *outer_select= unit->outer_select();
|
||||
/*
|
||||
do not take into account expression inside aggregate functions because
|
||||
they can access original table fields
|
||||
*/
|
||||
parsing_place= (outer_select->in_sum_expr ?
|
||||
NO_MATTER :
|
||||
outer_select->parsing_place);
|
||||
if (select_lex->next_select())
|
||||
engine= new subselect_union_engine(unit, result, this);
|
||||
else
|
||||
|
Reference in New Issue
Block a user