Skip to content

Commit 879878e

Browse files
author
Varun Gupta
committed
MDEV-18943: Group Concat with limit not working with views
Adjusted the Item_func_group_concat::print function to take into account limit if present with GROUP_CONCAT
1 parent 5182348 commit 879878e

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

mysql-test/main/func_gconcat.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,5 +1378,19 @@ group_concat(a,b limit ?)
13781378
1a,1b,2x,2y
13791379
drop table t2;
13801380
#
1381+
# MDEV-18943: Group Concat with limit not working with views
1382+
#
1383+
create table t1 (a int, b varchar(10));
1384+
insert into t1 values(1,'a'),(1,'b'),(NULL,'c'),(2,'x'),(2,'y');
1385+
select group_concat(a,b limit 2) from t1;
1386+
group_concat(a,b limit 2)
1387+
1a,1b
1388+
create view v1 as select group_concat(a,b limit 2) from t1;
1389+
select * from v1;
1390+
group_concat(a,b limit 2)
1391+
1a,1b
1392+
drop view v1;
1393+
drop table t1;
1394+
#
13811395
# End of 10.3 tests
13821396
#

mysql-test/main/func_gconcat.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,18 @@ prepare STMT from 'select group_concat(a,b limit ?) from t2';
985985
execute STMT using @x;
986986
drop table t2;
987987

988+
--echo #
989+
--echo # MDEV-18943: Group Concat with limit not working with views
990+
--echo #
991+
992+
create table t1 (a int, b varchar(10));
993+
insert into t1 values(1,'a'),(1,'b'),(NULL,'c'),(2,'x'),(2,'y');
994+
select group_concat(a,b limit 2) from t1;
995+
create view v1 as select group_concat(a,b limit 2) from t1;
996+
select * from v1;
997+
drop view v1;
998+
drop table t1;
999+
9881000
--echo #
9891001
--echo # End of 10.3 tests
9901002
--echo #

sql/item_sum.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4172,7 +4172,19 @@ void Item_func_group_concat::print(String *str, enum_query_type query_type)
41724172
}
41734173
str->append(STRING_WITH_LEN(" separator \'"));
41744174
str->append_for_single_quote(separator->ptr(), separator->length());
4175-
str->append(STRING_WITH_LEN("\')"));
4175+
str->append(STRING_WITH_LEN("\'"));
4176+
4177+
if (limit_clause)
4178+
{
4179+
str->append(STRING_WITH_LEN(" limit "));
4180+
if (offset_limit)
4181+
{
4182+
offset_limit->print(str, query_type);
4183+
str->append(',');
4184+
}
4185+
row_limit->print(str, query_type);
4186+
}
4187+
str->append(STRING_WITH_LEN(")"));
41764188
}
41774189

41784190

0 commit comments

Comments
 (0)