summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/group_by.result5
-rw-r--r--mysql-test/t/group_by.test2
-rw-r--r--sql/item_cmpfunc.cc6
-rw-r--r--sql/item_cmpfunc.h3
4 files changed, 14 insertions, 2 deletions
diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result
index b557d90f312..7b104996769 100644
--- a/mysql-test/r/group_by.result
+++ b/mysql-test/r/group_by.result
@@ -47,6 +47,11 @@ userid count(*)
3 3
2 1
1 2
+userid count(*)
+3 3
+1 2
+userid count(*)
+3 3
table type possible_keys key key_len ref rows Extra
t1 range spID spID 5 NULL 2 where used; Using index; Using temporary
table type possible_keys key key_len ref rows Extra
diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test
index e4b7d659a8e..c3e4f34b0fa 100644
--- a/mysql-test/t/group_by.test
+++ b/mysql-test/t/group_by.test
@@ -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);
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 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;
select spid,count(*) from t1 where spid between 1 and 2 group by spid;
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 4ef77d0c509..b53d596da08 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -1029,13 +1029,17 @@ void Item_func_in::update_used_tables()
used_tables_cache|=item->used_tables();
const_item_cache&=item->const_item();
}
+
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);
item=new Item_ref((Item**) fields.head_ref(),0,item->name);
}
+ Item_func::split_sum_func(fields);
}
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index 72d4e06e39c..7827cf9a78b 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -410,8 +410,9 @@ class Item_func_in :public Item_int_func
longlong val_int();
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;
- return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
+ return res;
}
void fix_length_and_dec();
~Item_func_in() { delete item; delete array; delete in_item; }