count(distint) on an empty table crash fixed

This commit is contained in:
serg@sergbook.mysql.com 2003-02-10 12:01:47 +01:00
parent c0b655aa38
commit cba78f827c
5 changed files with 21 additions and 4 deletions

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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) ||

View file

@ -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);}
};