diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 6f15e7af399..a74feb4de17 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2323,3 +2323,15 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 3 Using where DROP VIEW v1,v2; DROP TABLE t1,t2,t3; +create table t1 (f1 int, f2 int); +insert into t1 values(1,1),(1,2),(1,3); +create view v1 as select f1 ,group_concat(f2 order by f2 asc) from t1 group by f1; +create view v2 as select f1 ,group_concat(f2 order by f2 desc) from t1 group by f1; +select * from v1; +f1 group_concat(f2 order by f2 asc) +1 1,2,3 +select * from v2; +f1 group_concat(f2 order by f2 desc) +1 3,2,1 +drop view v1,v2; +drop table t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index aa3189bad69..0bd0e572193 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2189,4 +2189,14 @@ EXPLAIN SELECT * FROM v2 WHERE a=1; DROP VIEW v1,v2; DROP TABLE t1,t2,t3; - +# +# Bug #14466 lost sort order in GROUP_CONCAT() in a view +# +create table t1 (f1 int, f2 int); +insert into t1 values(1,1),(1,2),(1,3); +create view v1 as select f1 ,group_concat(f2 order by f2 asc) from t1 group by f1; +create view v2 as select f1 ,group_concat(f2 order by f2 desc) from t1 group by f1; +select * from v1; +select * from v2; +drop view v1,v2; +drop table t1; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index b56d99cf245..b2eaf39d624 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -3173,6 +3173,10 @@ void Item_func_group_concat::print(String *str) if (i) str->append(','); (*order[i]->item)->print(str); + if (order[i]->asc) + str->append(" ASC"); + else + str->append(" DESC"); } } str->append(" separator \'", 12);