diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-06-13 19:01:28 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-06-13 19:01:28 +0300 |
commit | 805340936aa47493886bafd119863d83c475f45c (patch) | |
tree | 46e5a4bd2e8311ef2880caa0526ce705a40c925e /sql/item_sum.cc | |
parent | f9e53a659c87f1147d4f6d004702077d4d0ce5d7 (diff) | |
parent | d83a4432503d199f6aed8e378563b08471d090dc (diff) | |
download | mariadb-git-805340936aa47493886bafd119863d83c475f45c.tar.gz |
Merge 10.3 into 10.4
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r-- | sql/item_sum.cc | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 3c468c72fa9..88110367b38 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -3628,23 +3628,25 @@ int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)), ulonglong *offset_limit= &item->copy_offset_limit; ulonglong *row_limit = &item->copy_row_limit; if (item->limit_clause && !(*row_limit)) + { + item->result_finalized= true; return 1; - - if (item->no_appended) - item->no_appended= FALSE; - else - result->append(*item->separator); + } tmp.length(0); if (item->limit_clause && (*offset_limit)) { item->row_count++; - item->no_appended= TRUE; (*offset_limit)--; return 0; } + if (!item->result_finalized) + item->result_finalized= true; + else + result->append(*item->separator); + for (; arg < arg_end; arg++) { String *res; @@ -3899,7 +3901,7 @@ void Item_func_group_concat::clear() result.copy(); null_value= TRUE; warning_for_row= FALSE; - no_appended= TRUE; + result_finalized= FALSE; if (offset_limit) copy_offset_limit= offset_limit->val_int(); if (row_limit) @@ -4032,13 +4034,12 @@ bool Item_func_group_concat::add() return 1; tree_len+= row_str_len; } + /* - If the row is not a duplicate (el->count == 1) - we can dump the row here in case of GROUP_CONCAT(DISTINCT...) - instead of doing tree traverse later. + In case of GROUP_CONCAT with DISTINCT or ORDER BY (or both) don't dump the + row to the output buffer here. That will be done in val_str. */ - if (row_eligible && !warning_for_row && - (!tree || (el->count == 1 && distinct && !arg_count_order))) + if (row_eligible && !warning_for_row && (!tree && !distinct)) dump_leaf_key(table->record[0] + table->s->null_bytes, 1, this); return 0; @@ -4274,9 +4275,18 @@ String* Item_func_group_concat::val_str(String* str) DBUG_ASSERT(fixed == 1); if (null_value) return 0; - if (no_appended && tree) - /* Tree is used for sorting as in ORDER BY */ - tree_walk(tree, &dump_leaf_key, this, left_root_right); + + if (!result_finalized) // Result yet to be written. + { + if (tree != NULL) // order by + tree_walk(tree, &dump_leaf_key, this, left_root_right); + else if (distinct) // distinct (and no order by). + unique_filter->walk(table, &dump_leaf_key, this); + else if (row_limit && copy_row_limit == (ulonglong)row_limit->val_int()) + return &result; + else + DBUG_ASSERT(false); // Can't happen + } if (table && table->blob_storage && table->blob_storage->is_truncated_value()) |