summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/func_gconcat.result20
-rw-r--r--mysql-test/t/func_gconcat.test16
-rw-r--r--sql/item_sum.cc8
-rw-r--r--sql/item_sum.h1
4 files changed, 42 insertions, 3 deletions
diff --git a/mysql-test/r/func_gconcat.result b/mysql-test/r/func_gconcat.result
index 12bc5ca2582..9c0c05ae296 100644
--- a/mysql-test/r/func_gconcat.result
+++ b/mysql-test/r/func_gconcat.result
@@ -560,3 +560,23 @@ group_concat('x')
NULL
1
drop table t1;
+CREATE TABLE t1 (id int, a varchar(9));
+INSERT INTO t1 VALUES
+(2, ''), (1, ''), (2, 'x'), (1, 'y'), (3, 'z'), (3, '');
+SELECT GROUP_CONCAT(a) FROM t1;
+GROUP_CONCAT(a)
+,,x,y,z,
+SELECT GROUP_CONCAT(a ORDER BY a) FROM t1;
+GROUP_CONCAT(a ORDER BY a)
+,,,x,y,z
+SELECT GROUP_CONCAT(a) FROM t1 GROUP BY id;
+GROUP_CONCAT(a)
+,y
+,x
+z,
+SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY id;
+GROUP_CONCAT(a ORDER BY a)
+,y
+,x
+,z
+DROP TABLE t1;
diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test
index 9e003d19ab9..aa8ce0f4bdc 100644
--- a/mysql-test/t/func_gconcat.test
+++ b/mysql-test/t/func_gconcat.test
@@ -356,4 +356,20 @@ select * from (select group_concat(a) from t1) t2;
select group_concat('x') UNION ALL select 1;
drop table t1;
+#
+# Bug #12863 : missing separators after first empty cancatanated elements
+#
+
+CREATE TABLE t1 (id int, a varchar(9));
+INSERT INTO t1 VALUES
+ (2, ''), (1, ''), (2, 'x'), (1, 'y'), (3, 'z'), (3, '');
+
+SELECT GROUP_CONCAT(a) FROM t1;
+SELECT GROUP_CONCAT(a ORDER BY a) FROM t1;
+
+SELECT GROUP_CONCAT(a) FROM t1 GROUP BY id;
+SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY id;
+
+DROP TABLE t1;
+
# End of 4.1 tests
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 000dcdb4997..7f13fdf82b2 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -1664,7 +1664,9 @@ int dump_leaf_key(byte* key, uint32 count __attribute__((unused)),
char buff[MAX_FIELD_WIDTH];
String tmp((char *)&buff,sizeof(buff),default_charset_info), tmp2;
- if (item->result.length())
+ if (item->no_appended)
+ item->no_appended= FALSE;
+ else
item->result.append(*item->separator);
tmp.length(0);
@@ -1856,6 +1858,7 @@ void Item_func_group_concat::clear()
result.copy();
null_value= TRUE;
warning_for_row= FALSE;
+ no_appended= TRUE;
if (tree_mode)
reset_tree(tree);
}
@@ -1898,8 +1901,7 @@ bool Item_func_group_concat::add()
void Item_func_group_concat::reset_field()
{
- if (tree_mode)
- reset_tree(tree);
+ DBUG_ASSERT(0);
}
diff --git a/sql/item_sum.h b/sql/item_sum.h
index a3b422565d1..d53d8d861ae 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -709,6 +709,7 @@ class Item_func_group_concat : public Item_sum
uint arg_count_field;
uint field_list_offset;
uint count_cut_values;
+ bool no_appended;
/*
Following is 0 normal object and pointer to original one for copy
(to correctly free resources)