count(distint) on an empty table crash fixed

parent c0b655aa
......@@ -523,3 +523,5 @@ vio/test-sslclient
vio/test-sslserver
vio/viotest-ssl
extra/mysql_waitpid
support-files/MacOSX/Description.plist
support-files/MacOSX/Info.plist
......@@ -48,3 +48,8 @@ select t1.f1,count(distinct t2.f2),count(distinct 1,NULL) from t1 left join t2 o
f1 count(distinct t2.f2) count(distinct 1,NULL)
1 0 0
drop table t1,t2;
create table t1 (f int);
select count(distinct f) from t1;
count(distinct f)
0
drop table t1;
......@@ -43,3 +43,12 @@ insert into t1 values (1);
create table t2 (f1 int,f2 int);
select t1.f1,count(distinct t2.f2),count(distinct 1,NULL) from t1 left join t2 on t1.f1=t2.f1 group by t1.f1;
drop table t1,t2;
#
# Empty tables
#
create table t1 (f int);
select count(distinct f) from t1;
drop table t1;
......@@ -918,7 +918,7 @@ int dump_leaf(byte* key, uint32 count __attribute__((unused)),
}
Item_sum_count_distinct::~Item_sum_count_distinct()
void Item_sum_count_distinct::no_rows_in_result()
{
if (table)
free_tmp_table(current_thd, table);
......@@ -927,7 +927,6 @@ Item_sum_count_distinct::~Item_sum_count_distinct()
delete_tree(&tree);
}
bool Item_sum_count_distinct::fix_fields(THD *thd,TABLE_LIST *tables)
{
if (Item_sum_num::fix_fields(thd,tables) ||
......
......@@ -185,7 +185,8 @@ class Item_sum_count_distinct :public Item_sum_int
:Item_sum_int(list),table(0),used_table_cache(~(table_map) 0),
tmp_table_param(0),use_tree(0),always_null(0)
{ quick_group=0; }
~Item_sum_count_distinct();
~Item_sum_count_distinct() { no_rows_in_result(); }
table_map used_tables() const { return used_table_cache; }
enum Sumfunctype sum_func () const { return COUNT_DISTINCT_FUNC; }
void reset();
......@@ -195,7 +196,8 @@ class Item_sum_count_distinct :public Item_sum_int
void update_field(int offset) { return ; } // Never called
const char *func_name() const { return "count_distinct"; }
bool setup(THD *thd);
unsigned int size_of() { return sizeof(*this);}
void no_rows_in_result();
unsigned int size_of() { return sizeof(*this);}
};
......
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