1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-11297: Add support for LIMIT clause in GROUP_CONCAT()

This commit is contained in:
Varun Gupta
2017-12-08 12:21:26 +05:30
parent 3aa618a969
commit 6d63a03490
9 changed files with 6287 additions and 12 deletions

View File

@@ -3533,6 +3533,11 @@ int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)),
Item **arg= item->args, **arg_end= item->args + item->arg_count_field;
uint old_length= result->length();
ulonglong *offset_limit= &item->copy_offset_limit;
ulonglong *row_limit = &item->copy_row_limit;
if (item->limit_clause && !(*row_limit))
return 1;
if (item->no_appended)
item->no_appended= FALSE;
else
@@ -3540,6 +3545,14 @@ int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)),
tmp.length(0);
if (item->limit_clause && (*offset_limit))
{
item->row_count++;
item->no_appended= TRUE;
(*offset_limit)--;
return 0;
}
for (; arg < arg_end; arg++)
{
String *res;
@@ -3569,6 +3582,8 @@ int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)),
result->append(*res);
}
if (item->limit_clause)
(*row_limit)--;
item->row_count++;
/* stop if length of result more than max_length */
@@ -3617,7 +3632,8 @@ Item_func_group_concat::
Item_func_group_concat(THD *thd, Name_resolution_context *context_arg,
bool distinct_arg, List<Item> *select_list,
const SQL_I_List<ORDER> &order_list,
String *separator_arg)
String *separator_arg, bool limit_clause,
Item *row_limit_arg, Item *offset_limit_arg)
:Item_sum(thd), tmp_table_param(0), separator(separator_arg), tree(0),
unique_filter(NULL), table(0),
order(0), context(context_arg),
@@ -3626,7 +3642,9 @@ Item_func_group_concat(THD *thd, Name_resolution_context *context_arg,
row_count(0),
distinct(distinct_arg),
warning_for_row(FALSE),
force_copy_fields(0), original(0)
force_copy_fields(0), row_limit(NULL),
offset_limit(NULL), limit_clause(limit_clause),
copy_offset_limit(0), copy_row_limit(0), original(0)
{
Item *item_select;
Item **arg_ptr;
@@ -3668,6 +3686,11 @@ Item_func_group_concat(THD *thd, Name_resolution_context *context_arg,
/* orig_args is only used for print() */
orig_args= (Item**) (order + arg_count_order);
memcpy(orig_args, args, sizeof(Item*) * arg_count);
if (limit_clause)
{
row_limit= row_limit_arg;
offset_limit= offset_limit_arg;
}
}
@@ -3687,7 +3710,9 @@ Item_func_group_concat::Item_func_group_concat(THD *thd,
warning_for_row(item->warning_for_row),
always_null(item->always_null),
force_copy_fields(item->force_copy_fields),
original(item)
row_limit(item->row_limit), offset_limit(item->offset_limit),
limit_clause(item->limit_clause),copy_offset_limit(item->copy_offset_limit),
copy_row_limit(item->copy_row_limit), original(item)
{
quick_group= item->quick_group;
result.set_charset(collation.collation);
@@ -3782,6 +3807,10 @@ void Item_func_group_concat::clear()
null_value= TRUE;
warning_for_row= FALSE;
no_appended= TRUE;
if (offset_limit)
copy_offset_limit= offset_limit->val_int();
if (row_limit)
copy_row_limit= row_limit->val_int();
if (tree)
reset_tree(tree);
if (unique_filter)
@@ -4036,6 +4065,12 @@ bool Item_func_group_concat::setup(THD *thd)
(void*)this,
tree_key_length,
ram_limitation(thd));
if ((row_limit && row_limit->cmp_type() != INT_RESULT) ||
(offset_limit && offset_limit->cmp_type() != INT_RESULT))
{
my_error(ER_INVALID_VALUE_TO_LIMIT, MYF(0));
DBUG_RETURN(TRUE);
}
DBUG_RETURN(FALSE);
}