fixed memory leak in group_concat function (BUG#796)
fixed test func_gconcat to be repeatable independent of presend tables and avoid removing user tables
This commit is contained in:
parent
45e001f465
commit
9b6083dbe7
@ -1,6 +1,4 @@
|
|||||||
drop table if exists t1;
|
drop table if exists t1, t2;
|
||||||
Warnings:
|
|
||||||
Note 1051 Unknown table 't1'
|
|
||||||
create table t1 (grp int, a bigint unsigned, c char(10) not null, d char(10) not null);
|
create table t1 (grp int, a bigint unsigned, c char(10) not null, d char(10) not null);
|
||||||
insert into t1 values (1,1,"a","a");
|
insert into t1 values (1,1,"a","a");
|
||||||
insert into t1 values (2,2,"b","a");
|
insert into t1 values (2,2,"b","a");
|
||||||
@ -155,28 +153,22 @@ show warnings;
|
|||||||
Level Code Message
|
Level Code Message
|
||||||
Warning 1258 1 line(s) was(were) cut by group_concat()
|
Warning 1258 1 line(s) was(were) cut by group_concat()
|
||||||
set group_concat_max_len = 1024;
|
set group_concat_max_len = 1024;
|
||||||
drop table if exists T_URL;
|
|
||||||
Warnings:
|
|
||||||
Note 1051 Unknown table 'T_URL'
|
|
||||||
create table T_URL ( URL_ID int(11), URL varchar(80));
|
|
||||||
drop table if exists T_REQUEST;
|
|
||||||
Warnings:
|
|
||||||
Note 1051 Unknown table 'T_REQUEST'
|
|
||||||
create table T_REQUEST ( REQ_ID int(11), URL_ID int(11));
|
|
||||||
insert into T_URL values (4,'www.host.com'), (5,'www.google.com'),(5,'www.help.com');
|
|
||||||
insert into T_REQUEST values (1,4), (5,4), (5,5);
|
|
||||||
select REQ_ID, Group_Concat(URL) as URL from T_URL, T_REQUEST where
|
|
||||||
T_REQUEST.URL_ID = T_URL.URL_ID group by REQ_ID;
|
|
||||||
REQ_ID URL
|
|
||||||
1 X
|
|
||||||
5 X,X,X
|
|
||||||
drop table T_URL;
|
|
||||||
drop table T_REQUEST;
|
|
||||||
select group_concat(sum(a)) from t1 group by grp;
|
select group_concat(sum(a)) from t1 group by grp;
|
||||||
ERROR HY000: Invalid use of group function
|
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 ( URL_ID int(11), URL varchar(80));
|
||||||
|
create table t2 ( REQ_ID int(11), URL_ID int(11));
|
||||||
|
insert into t1 values (4,'www.host.com'), (5,'www.google.com'),(5,'www.help.com');
|
||||||
|
insert into t2 values (1,4), (5,4), (5,5);
|
||||||
|
select REQ_ID, Group_Concat(URL) as URL from t1, t2 where
|
||||||
|
t2.URL_ID = t1.URL_ID group by REQ_ID;
|
||||||
|
REQ_ID URL
|
||||||
|
1 X
|
||||||
|
5 X,X,X
|
||||||
|
drop table t1;
|
||||||
|
drop table t2;
|
||||||
create table t1 (id int, name varchar(16));
|
create table t1 (id int, name varchar(16));
|
||||||
insert into t1 values (1,'longername'),(1,'evenlongername');
|
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 ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'without distinct: how it should be' from t1;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
#
|
#
|
||||||
# simple test of group_concat function
|
# simple test of group_concat function
|
||||||
#
|
#
|
||||||
|
--disable_warnings
|
||||||
|
drop table if exists t1, t2;
|
||||||
|
--enable_warnings
|
||||||
|
|
||||||
drop table if exists t1;
|
|
||||||
create table t1 (grp int, a bigint unsigned, c char(10) not null, d char(10) not null);
|
create table t1 (grp int, a bigint unsigned, c char(10) not null, d char(10) not null);
|
||||||
insert into t1 values (1,1,"a","a");
|
insert into t1 values (1,1,"a","a");
|
||||||
insert into t1 values (2,2,"b","a");
|
insert into t1 values (2,2,"b","a");
|
||||||
@ -70,21 +72,6 @@ select grp,group_concat(c) from t1 group by grp;
|
|||||||
show warnings;
|
show warnings;
|
||||||
set group_concat_max_len = 1024;
|
set group_concat_max_len = 1024;
|
||||||
|
|
||||||
# Test variable length
|
|
||||||
|
|
||||||
drop table if exists T_URL;
|
|
||||||
create table T_URL ( URL_ID int(11), URL varchar(80));
|
|
||||||
drop table if exists T_REQUEST;
|
|
||||||
create table T_REQUEST ( REQ_ID int(11), URL_ID int(11));
|
|
||||||
insert into T_URL values (4,'www.host.com'), (5,'www.google.com'),(5,'www.help.com');
|
|
||||||
insert into T_REQUEST values (1,4), (5,4), (5,5);
|
|
||||||
# Make this order independent
|
|
||||||
--replace_result www.help.com X www.host.com X www.google.com X
|
|
||||||
select REQ_ID, Group_Concat(URL) as URL from T_URL, T_REQUEST where
|
|
||||||
T_REQUEST.URL_ID = T_URL.URL_ID group by REQ_ID;
|
|
||||||
drop table T_URL;
|
|
||||||
drop table T_REQUEST;
|
|
||||||
|
|
||||||
# Test errors
|
# Test errors
|
||||||
|
|
||||||
--error 1111
|
--error 1111
|
||||||
@ -94,6 +81,19 @@ select grp,group_concat(c order by 2) from t1 group by grp;
|
|||||||
|
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
|
# Test variable length
|
||||||
|
|
||||||
|
create table t1 ( URL_ID int(11), URL varchar(80));
|
||||||
|
create table t2 ( REQ_ID int(11), URL_ID int(11));
|
||||||
|
insert into t1 values (4,'www.host.com'), (5,'www.google.com'),(5,'www.help.com');
|
||||||
|
insert into t2 values (1,4), (5,4), (5,5);
|
||||||
|
# Make this order independent
|
||||||
|
--replace_result www.help.com X www.host.com X www.google.com X
|
||||||
|
select REQ_ID, Group_Concat(URL) as URL from t1, t2 where
|
||||||
|
t2.URL_ID = t1.URL_ID group by REQ_ID;
|
||||||
|
drop table t1;
|
||||||
|
drop table t2;
|
||||||
|
|
||||||
create table t1 (id int, name varchar(16));
|
create table t1 (id int, name varchar(16));
|
||||||
insert into t1 values (1,'longername'),(1,'evenlongername');
|
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 ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'without distinct: how it should be' from t1;
|
||||||
|
@ -1788,11 +1788,12 @@ 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)
|
||||||
{
|
{
|
||||||
|
DBUG_ENTER("Item_func_group_concat::setup");
|
||||||
List<Item> list;
|
List<Item> list;
|
||||||
SELECT_LEX *select_lex= thd->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;
|
DBUG_RETURN(1);
|
||||||
/*
|
/*
|
||||||
all not constant fields are push to list and create temp table
|
all not constant fields are push to list and create temp table
|
||||||
*/
|
*/
|
||||||
@ -1801,7 +1802,7 @@ bool Item_func_group_concat::setup(THD *thd)
|
|||||||
{
|
{
|
||||||
Item *item= args[i];
|
Item *item= args[i];
|
||||||
if (list.push_back(item))
|
if (list.push_back(item))
|
||||||
return 1;
|
DBUG_RETURN(1);
|
||||||
if (item->const_item())
|
if (item->const_item())
|
||||||
{
|
{
|
||||||
(void) item->val_int();
|
(void) item->val_int();
|
||||||
@ -1810,7 +1811,7 @@ bool Item_func_group_concat::setup(THD *thd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (always_null)
|
if (always_null)
|
||||||
return 0;
|
DBUG_RETURN(0);
|
||||||
|
|
||||||
List<Item> all_fields(list);
|
List<Item> all_fields(list);
|
||||||
if (arg_count_order)
|
if (arg_count_order)
|
||||||
@ -1821,13 +1822,18 @@ bool Item_func_group_concat::setup(THD *thd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
count_field_types(tmp_table_param,all_fields,0);
|
count_field_types(tmp_table_param,all_fields,0);
|
||||||
|
if (table)
|
||||||
|
{
|
||||||
|
free_tmp_table(thd, table);
|
||||||
|
tmp_table_param->cleanup();
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
We have to create a temporary table for that we get descriptions of fields
|
We have to create a temporary table for that we get descriptions of fields
|
||||||
(types, sizes and so on).
|
(types, sizes and so on).
|
||||||
*/
|
*/
|
||||||
if (!(table=create_tmp_table(thd, tmp_table_param, all_fields, 0,
|
if (!(table=create_tmp_table(thd, tmp_table_param, all_fields, 0,
|
||||||
0, 0, 0,select_lex->options | thd->options)))
|
0, 0, 0,select_lex->options | thd->options)))
|
||||||
return 1;
|
DBUG_RETURN(1);
|
||||||
table->file->extra(HA_EXTRA_NO_ROWS);
|
table->file->extra(HA_EXTRA_NO_ROWS);
|
||||||
table->no_rows= 1;
|
table->no_rows= 1;
|
||||||
|
|
||||||
@ -1886,7 +1892,7 @@ bool Item_func_group_concat::setup(THD *thd)
|
|||||||
original->table= table;
|
original->table= table;
|
||||||
original->tree_mode= tree_mode;
|
original->tree_mode= tree_mode;
|
||||||
}
|
}
|
||||||
return 0;
|
DBUG_RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is used by rollup to create a separate usable copy of the function */
|
/* This is used by rollup to create a separate usable copy of the function */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user