Commit c6beb583 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

fixed functions to be able work with group function as argument

made bisone 1.75 compatible code
parent 710ffb2d
......@@ -3,6 +3,7 @@ Sinisa@sinisa.nasamreza.org
arjen@fred.bitbike.com
bar@bar.mysql.r18.ru
bar@bar.udmsearch.izhnet.ru
bell@sanja.is.com.ua
bk@admin.bk
heikki@donna.mysql.fi
heikki@hundin.mysql.fi
......
......@@ -110,3 +110,21 @@ a count(*)
NULL 9
3
b 1
a MAX(b) INTERVAL (MAX(b), 1,3,10,30,39,40,50,60,100,1000)
1 4 2
10 43 6
a MAX(b) CASE MAX(b) when 4 then 4 when 43 then 43 else 0 end
1 4 4
10 43 43
a MAX(b) FIELD(MAX(b), '43', '4', '5')
1 4 2
10 43 1
a MAX(b) CONCAT_WS(MAX(b), '43', '4', '5')
1 4 434445
10 43 43434435
a MAX(b) ELT(MAX(b), 'a', 'b', 'c', 'd', 'e', 'f')
1 4 d
10 43 NULL
a MAX(b) MAKE_SET(MAX(b), 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')
1 4 c
10 43 a,b,d,f
......@@ -323,3 +323,26 @@ select a,count(*) from t1 group by a;
set option sql_big_tables=1;
select a,count(*) from t1 group by a;
drop table t1;
#
# group function arguments in some functions
#
create table t1 (a int, b int);
insert into t1 values (1, 4);
insert into t1 values (10, 40);
insert into t1 values (1, 4);
insert into t1 values (10, 43);
insert into t1 values (1, 4);
insert into t1 values (10, 41);
insert into t1 values (1, 4);
insert into t1 values (10, 43);
insert into t1 values (1, 4);
select a, MAX(b), INTERVAL (MAX(b), 1,3,10,30,39,40,50,60,100,1000) from t1 group by a;
select a, MAX(b), CASE MAX(b) when 4 then 4 when 43 then 43 else 0 end from t1 group by a;
select a, MAX(b), FIELD(MAX(b), '43', '4', '5') from t1 group by a;
select a, MAX(b), CONCAT_WS(MAX(b), '43', '4', '5') from t1 group by a;
select a, MAX(b), ELT(MAX(b), 'a', 'b', 'c', 'd', 'e', 'f') from t1 group by a;
select a, MAX(b), MAKE_SET(MAX(b), 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h') from t1 group by a;
drop table t1;
......@@ -287,6 +287,19 @@ void Item_func_interval::fix_length_and_dec()
}
maybe_null=0; max_length=2;
used_tables_cache|=item->used_tables();
with_sum_func= with_sum_func || item->with_sum_func;
}
void Item_func_interval::split_sum_func(List<Item> &fields)
{
if (item->with_sum_func && item->type() != SUM_FUNC_ITEM)
item->split_sum_func(fields);
else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
{
fields.push_front(item);
item= new Item_ref((Item**) fields.head_ref(), 0, item->name);
}
Item_int_func::split_sum_func(fields);
}
/*
......@@ -739,17 +752,45 @@ Item_func_case::fix_fields(THD *thd,TABLE_LIST *tables)
{
used_tables_cache|=(first_expr)->used_tables();
const_item_cache&= (first_expr)->const_item();
with_sum_func= with_sum_func || (first_expr)->with_sum_func;
}
if (else_expr)
{
used_tables_cache|=(else_expr)->used_tables();
const_item_cache&= (else_expr)->const_item();
with_sum_func= with_sum_func || (else_expr)->with_sum_func;
}
if (!else_expr || else_expr->maybe_null)
maybe_null=1; // The result may be NULL
return 0;
}
void Item_func_case::split_sum_func(List<Item> &fields)
{
if (first_expr)
{
if (first_expr->with_sum_func && first_expr->type() != SUM_FUNC_ITEM)
first_expr->split_sum_func(fields);
else if (first_expr->used_tables() || first_expr->type() == SUM_FUNC_ITEM)
{
fields.push_front(first_expr);
first_expr= new Item_ref((Item**) fields.head_ref(), 0,
first_expr->name);
}
}
if (else_expr)
{
if (else_expr->with_sum_func && else_expr->type() != SUM_FUNC_ITEM)
else_expr->split_sum_func(fields);
else if (else_expr->used_tables() || else_expr->type() == SUM_FUNC_ITEM)
{
fields.push_front(else_expr);
else_expr= new Item_ref((Item**) fields.head_ref(), 0, else_expr->name);
}
}
Item_func::split_sum_func(fields);
}
void Item_func_case::update_used_tables()
{
Item_func::update_used_tables();
......@@ -1038,7 +1079,7 @@ void Item_func_in::split_sum_func(List<Item> &fields)
else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
{
fields.push_front(item);
item=new Item_ref((Item**) fields.head_ref(),0,item->name);
item= new Item_ref((Item**) fields.head_ref(), 0, item->name);
}
Item_func::split_sum_func(fields);
}
......
......@@ -180,6 +180,7 @@ public:
{
return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
}
void split_sum_func(List<Item> &fields);
void fix_length_and_dec();
~Item_func_interval() { delete item; }
const char *func_name() const { return "interval"; }
......@@ -259,6 +260,7 @@ public:
const char *func_name() const { return "case"; }
void print(String *str);
bool fix_fields(THD *thd,struct st_table_list *tlist);
void split_sum_func(List<Item> &fields);
Item *find_item(String *str);
};
......
......@@ -864,6 +864,17 @@ longlong Item_func_field::val_int()
return 0;
}
void Item_func_field::split_sum_func(List<Item> &fields)
{
if (item->with_sum_func && item->type() != SUM_FUNC_ITEM)
item->split_sum_func(fields);
else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
{
fields.push_front(item);
item= new Item_ref((Item**) fields.head_ref(), 0, item->name);
}
Item_func::split_sum_func(fields);
}
longlong Item_func_ascii::val_int()
{
......
......@@ -517,6 +517,7 @@ public:
{
return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
}
void split_sum_func(List<Item> &fields);
void update_used_tables()
{
item->update_used_tables() ; Item_func::update_used_tables();
......
......@@ -310,6 +310,17 @@ null:
return 0;
}
void Item_func_concat_ws::split_sum_func(List<Item> &fields)
{
if (separator->with_sum_func && separator->type() != SUM_FUNC_ITEM)
separator->split_sum_func(fields);
else if (separator->used_tables() || separator->type() == SUM_FUNC_ITEM)
{
fields.push_front(separator);
separator= new Item_ref((Item**) fields.head_ref(), 0, separator->name);
}
Item_str_func::split_sum_func(fields);
}
void Item_func_concat_ws::fix_length_and_dec()
{
......@@ -323,6 +334,7 @@ void Item_func_concat_ws::fix_length_and_dec()
}
used_tables_cache|=separator->used_tables();
const_item_cache&=separator->const_item();
with_sum_func= with_sum_func || separator->with_sum_func;
}
void Item_func_concat_ws::update_used_tables()
......@@ -1221,6 +1233,19 @@ void Item_func_elt::fix_length_and_dec()
}
void Item_func_elt::split_sum_func(List<Item> &fields)
{
if (item->with_sum_func && item->type() != SUM_FUNC_ITEM)
item->split_sum_func(fields);
else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
{
fields.push_front(item);
item= new Item_ref((Item**) fields.head_ref(), 0, item->name);
}
Item_str_func::split_sum_func(fields);
}
void Item_func_elt::update_used_tables()
{
Item_func::update_used_tables();
......@@ -1267,6 +1292,19 @@ String *Item_func_elt::val_str(String *str)
}
void Item_func_make_set::split_sum_func(List<Item> &fields)
{
if (item->with_sum_func && item->type() != SUM_FUNC_ITEM)
item->split_sum_func(fields);
else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
{
fields.push_front(item);
item= new Item_ref((Item**) fields.head_ref(), 0, item->name);
}
Item_str_func::split_sum_func(fields);
}
void Item_func_make_set::fix_length_and_dec()
{
max_length=arg_count-1;
......@@ -1274,6 +1312,7 @@ void Item_func_make_set::fix_length_and_dec()
max_length+=args[i]->max_length;
used_tables_cache|=item->used_tables();
const_item_cache&=item->const_item();
with_sum_func= with_sum_func || item->with_sum_func;
}
......
......@@ -75,6 +75,7 @@ public:
return (separator->fix_fields(thd,tlist)
|| Item_func::fix_fields(thd,tlist));
}
void split_sum_func(List<Item> &fields);
const char *func_name() const { return "concat_ws"; }
};
......@@ -296,6 +297,7 @@ public:
{
return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
}
void split_sum_func(List<Item> &fields);
void fix_length_and_dec();
void update_used_tables();
const char *func_name() const { return "elt"; }
......@@ -315,6 +317,7 @@ public:
{
return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
}
void split_sum_func(List<Item> &fields);
void fix_length_and_dec();
void update_used_tables();
const char *func_name() const { return "make_set"; }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment