@@ -4621,6 +4621,9 @@ bool Item_func_collect::add() {
46214621 if (tmp_arg[0 ]->null_value )
46224622 return 0 ;
46234623
4624+ if (is_distinct && list_contains_element (wkb))
4625+ return 0 ;
4626+
46244627 current_geometry_srid= uint4korr (wkb->ptr ());
46254628 if (geometries.is_empty ())
46264629 srid= current_geometry_srid;
@@ -4636,7 +4639,6 @@ bool Item_func_collect::add() {
46364639
46374640
46384641void Item_func_collect::remove () {
4639- String value;
46404642 String *wkb= args[0 ]->val_str (&value);
46414643 has_cached_result= false ;
46424644
@@ -4661,17 +4663,34 @@ void Item_func_collect::remove() {
46614663}
46624664
46634665
4664- Item_func_collect::Item_func_collect (THD *thd, Item *item_par) :
4666+ bool Item_func_collect::list_contains_element (String *wkb) {
4667+ List_iterator<String> geometries_iterator (geometries);
4668+ String* temp_geometry;
4669+ while ((temp_geometry= geometries_iterator++))
4670+ {
4671+ String temp (temp_geometry->ptr (), temp_geometry->length (), &my_charset_bin);
4672+
4673+ if (wkb->eq (&temp, &my_charset_bin))
4674+ return true ;
4675+ }
4676+
4677+ return false ;
4678+ }
4679+
4680+
4681+ Item_func_collect::Item_func_collect (THD *thd, bool is_distinct, Item *item_par) :
46654682 Item_sum_int(thd, item_par),
46664683 mem_root(thd->mem_root),
4684+ is_distinct(is_distinct),
46674685 group_collect_max_len(thd->variables.group_concat_max_len)
46684686{
46694687}
46704688
46714689
4672- Item_func_collect::Item_func_collect (THD *thd, Item_func_collect *item) :
4690+ Item_func_collect::Item_func_collect (THD *thd, bool is_distinct, Item_func_collect *item) :
46734691 Item_sum_int(thd, item),
46744692 mem_root(thd->mem_root),
4693+ is_distinct(is_distinct),
46754694 group_collect_max_len(thd->variables.group_concat_max_len)
46764695{
46774696}
@@ -4748,5 +4767,5 @@ String *Item_func_collect::val_str(String *str)
47484767
47494768
47504769Item *Item_func_collect::copy_or_same (THD *thd) {
4751- return new (thd->mem_root ) Item_func_collect (thd, this );
4770+ return new (thd->mem_root ) Item_func_collect (thd, is_distinct, this );
47524771}
0 commit comments