mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
reduced using of slow current_thd/current_lex macro
initialization of item_thd moved to constructor (in any case we need thd in constructor) initialization of group_concat_max_len to constructor to avoid incorrect length reporting (BUG#757) removed Item_func_group_concat::fix_length_and_dec() because item have its own fix_fields and will not have inherited items mysql-test/r/func_gconcat.result: test for BUG#757 mysql-test/t/func_gconcat.test: test for BUG#757 sql/item_sum.cc: reduced using of slow current_thd/current_lex macro initialization of item_thd moved to constructor (in any case we need thd in constructor) initialization of group_concat_max_len to constructor to avoid incorrect length reporting (BUG#757) sql/item_sum.h: removed Item_func_group_concat::fix_length_and_dec() because item have its own fix_fields and will not have inherited items
This commit is contained in:
@ -177,3 +177,12 @@ ERROR HY000: Invalid use of group function
|
|||||||
select grp,group_concat(c order by 2) from t1 group by grp;
|
select grp,group_concat(c order by 2) from t1 group by grp;
|
||||||
ERROR 42S22: Unknown column '2' in 'group statement'
|
ERROR 42S22: Unknown column '2' in 'group statement'
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
create table t1 (id int, name varchar(16));
|
||||||
|
insert into t1 values (1,'longername'),(1,'evenlongername');
|
||||||
|
select ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'without distinct: how it should be' from t1;
|
||||||
|
without distinct: how it should be
|
||||||
|
1:longername,1:evenlongername
|
||||||
|
select distinct ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'with distinct: cutoff at length of shortname' from t1;
|
||||||
|
with distinct: cutoff at length of shortname
|
||||||
|
1:longername,1:evenlongername
|
||||||
|
drop table t1;
|
||||||
|
@ -93,3 +93,9 @@ select group_concat(sum(a)) from t1 group by grp;
|
|||||||
select grp,group_concat(c order by 2) from t1 group by grp;
|
select grp,group_concat(c order by 2) from t1 group by grp;
|
||||||
|
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
|
create table t1 (id int, name varchar(16));
|
||||||
|
insert into t1 values (1,'longername'),(1,'evenlongername');
|
||||||
|
select ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'without distinct: how it should be' from t1;
|
||||||
|
select distinct ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'with distinct: cutoff at length of shortname' from t1;
|
||||||
|
drop table t1;
|
||||||
|
@ -1114,7 +1114,7 @@ void Item_sum_count_distinct::make_unique()
|
|||||||
bool Item_sum_count_distinct::setup(THD *thd)
|
bool Item_sum_count_distinct::setup(THD *thd)
|
||||||
{
|
{
|
||||||
List<Item> list;
|
List<Item> list;
|
||||||
SELECT_LEX *select_lex= current_lex->current_select->select_lex();
|
SELECT_LEX *select_lex= thd->lex.current_select->select_lex();
|
||||||
if (select_lex->linkage == GLOBAL_OPTIONS_TYPE)
|
if (select_lex->linkage == GLOBAL_OPTIONS_TYPE)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -1599,7 +1599,7 @@ Item_func_group_concat::Item_func_group_concat(bool is_distinct,
|
|||||||
warning_available(0), key_length(0), rec_offset(0),
|
warning_available(0), key_length(0), rec_offset(0),
|
||||||
tree_mode(0), distinct(is_distinct), warning_for_row(0),
|
tree_mode(0), distinct(is_distinct), warning_for_row(0),
|
||||||
separator(is_separator), tree(&tree_base), table(0),
|
separator(is_separator), tree(&tree_base), table(0),
|
||||||
order(0), tables_list(0), group_concat_max_len(0),
|
order(0), tables_list(0),
|
||||||
show_elements(0), arg_count_order(0), arg_count_field(0),
|
show_elements(0), arg_count_order(0), arg_count_field(0),
|
||||||
arg_show_fields(0), count_cut_values(0)
|
arg_show_fields(0), count_cut_values(0)
|
||||||
|
|
||||||
@ -1607,8 +1607,11 @@ Item_func_group_concat::Item_func_group_concat(bool is_distinct,
|
|||||||
original= 0;
|
original= 0;
|
||||||
quick_group= 0;
|
quick_group= 0;
|
||||||
mark_as_sum_func();
|
mark_as_sum_func();
|
||||||
SELECT_LEX *select_lex= current_lex->current_select->select_lex();
|
item_thd= current_thd;
|
||||||
|
SELECT_LEX *select_lex= item_thd->lex.current_select->select_lex();
|
||||||
order= 0;
|
order= 0;
|
||||||
|
group_concat_max_len= item_thd->variables.group_concat_max_len;
|
||||||
|
|
||||||
|
|
||||||
arg_show_fields= arg_count_field= is_select->elements;
|
arg_show_fields= arg_count_field= is_select->elements;
|
||||||
arg_count_order= is_order ? is_order->elements : 0;
|
arg_count_order= is_order ? is_order->elements : 0;
|
||||||
@ -1773,7 +1776,7 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
|
|||||||
}
|
}
|
||||||
result_field= 0;
|
result_field= 0;
|
||||||
null_value= 1;
|
null_value= 1;
|
||||||
fix_length_and_dec();
|
max_length= group_concat_max_len;
|
||||||
thd->allow_sum_func= 1;
|
thd->allow_sum_func= 1;
|
||||||
if (!(tmp_table_param= new TMP_TABLE_PARAM))
|
if (!(tmp_table_param= new TMP_TABLE_PARAM))
|
||||||
return 1;
|
return 1;
|
||||||
@ -1786,7 +1789,7 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
|
|||||||
bool Item_func_group_concat::setup(THD *thd)
|
bool Item_func_group_concat::setup(THD *thd)
|
||||||
{
|
{
|
||||||
List<Item> list;
|
List<Item> list;
|
||||||
SELECT_LEX *select_lex= current_lex->current_select->select_lex();
|
SELECT_LEX *select_lex= thd->lex.current_select->select_lex();
|
||||||
|
|
||||||
if (select_lex->linkage == GLOBAL_OPTIONS_TYPE)
|
if (select_lex->linkage == GLOBAL_OPTIONS_TYPE)
|
||||||
return 1;
|
return 1;
|
||||||
@ -1873,9 +1876,6 @@ bool Item_func_group_concat::setup(THD *thd)
|
|||||||
max_elements_in_tree= ((key_length) ?
|
max_elements_in_tree= ((key_length) ?
|
||||||
thd->variables.max_heap_table_size/key_length : 1);
|
thd->variables.max_heap_table_size/key_length : 1);
|
||||||
};
|
};
|
||||||
item_thd= thd;
|
|
||||||
|
|
||||||
group_concat_max_len= thd->variables.group_concat_max_len;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copy table and tree_mode if they belong to this item (if item have not
|
Copy table and tree_mode if they belong to this item (if item have not
|
||||||
|
@ -713,7 +713,6 @@ class Item_func_group_concat : public Item_sum
|
|||||||
enum Sumfunctype sum_func () const {return GROUP_CONCAT_FUNC;}
|
enum Sumfunctype sum_func () const {return GROUP_CONCAT_FUNC;}
|
||||||
const char *func_name() const { return "group_concat"; }
|
const char *func_name() const { return "group_concat"; }
|
||||||
enum Type type() const { return SUM_FUNC_ITEM; }
|
enum Type type() const { return SUM_FUNC_ITEM; }
|
||||||
void fix_length_and_dec() { max_length=group_concat_max_len; }
|
|
||||||
virtual Item_result result_type () const { return STRING_RESULT; }
|
virtual Item_result result_type () const { return STRING_RESULT; }
|
||||||
bool reset();
|
bool reset();
|
||||||
bool add();
|
bool add();
|
||||||
|
Reference in New Issue
Block a user