Commit 62399923 authored by unknown's avatar unknown

Fix for sum_func IN (..)

parent 533ab812
...@@ -47,6 +47,11 @@ userid count(*) ...@@ -47,6 +47,11 @@ userid count(*)
3 3 3 3
2 1 2 1
1 2 1 2
userid count(*)
3 3
1 2
userid count(*)
3 3
table type possible_keys key key_len ref rows Extra table type possible_keys key key_len ref rows Extra
t1 range spID spID 5 NULL 2 where used; Using index; Using temporary t1 range spID spID 5 NULL 2 where used; Using index; Using temporary
table type possible_keys key key_len ref rows Extra table type possible_keys key key_len ref rows Extra
......
...@@ -235,6 +235,8 @@ CREATE TABLE t1 ( ...@@ -235,6 +235,8 @@ CREATE TABLE t1 (
INSERT INTO t1 VALUES (1,1,1),(2,2,2),(2,1,1),(3,3,3),(4,3,3),(5,3,3); INSERT INTO t1 VALUES (1,1,1),(2,2,2),(2,1,1),(3,3,3),(4,3,3),(5,3,3);
explain select userid,count(*) from t1 group by userid desc; explain select userid,count(*) from t1 group by userid desc;
select userid,count(*) from t1 group by userid desc; select userid,count(*) from t1 group by userid desc;
select userid,count(*) from t1 group by userid desc having (count(*)+1) IN (4,3);
select userid,count(*) from t1 group by userid desc having 3 IN (1,COUNT(*));
explain select spid,count(*) from t1 where spid between 1 and 2 group by spid desc; explain select spid,count(*) from t1 where spid between 1 and 2 group by spid desc;
explain select spid,count(*) from t1 where spid between 1 and 2 group by spid; explain select spid,count(*) from t1 where spid between 1 and 2 group by spid;
select spid,count(*) from t1 where spid between 1 and 2 group by spid; select spid,count(*) from t1 where spid between 1 and 2 group by spid;
......
...@@ -1029,13 +1029,17 @@ void Item_func_in::update_used_tables() ...@@ -1029,13 +1029,17 @@ void Item_func_in::update_used_tables()
used_tables_cache|=item->used_tables(); used_tables_cache|=item->used_tables();
const_item_cache&=item->const_item(); const_item_cache&=item->const_item();
} }
void Item_func_in::split_sum_func(List<Item> &fields) void Item_func_in::split_sum_func(List<Item> &fields)
{ {
if (item->used_tables() || item->type() == SUM_FUNC_ITEM) 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); 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);
} }
......
...@@ -410,8 +410,9 @@ class Item_func_in :public Item_int_func ...@@ -410,8 +410,9 @@ class Item_func_in :public Item_int_func
longlong val_int(); longlong val_int();
bool fix_fields(THD *thd,struct st_table_list *tlist) bool fix_fields(THD *thd,struct st_table_list *tlist)
{ {
bool res= (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
with_sum_func= with_sum_func || item->with_sum_func; with_sum_func= with_sum_func || item->with_sum_func;
return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist)); return res;
} }
void fix_length_and_dec(); void fix_length_and_dec();
~Item_func_in() { delete item; delete array; delete in_item; } ~Item_func_in() { delete item; delete array; delete in_item; }
......
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