summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bzrignore2
-rw-r--r--mysql-test/r/count_distinct.result5
-rw-r--r--mysql-test/t/count_distinct.test9
-rw-r--r--sql/item_sum.cc3
-rw-r--r--sql/item_sum.h6
5 files changed, 21 insertions, 4 deletions
diff --git a/.bzrignore b/.bzrignore
index 1f577634845..302ac6f658c 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -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
diff --git a/mysql-test/r/count_distinct.result b/mysql-test/r/count_distinct.result
index 81976d268ef..16460580d6c 100644
--- a/mysql-test/r/count_distinct.result
+++ b/mysql-test/r/count_distinct.result
@@ -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;
diff --git a/mysql-test/t/count_distinct.test b/mysql-test/t/count_distinct.test
index f3584686f69..cb84d0211d7 100644
--- a/mysql-test/t/count_distinct.test
+++ b/mysql-test/t/count_distinct.test
@@ -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;
+
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 222dd0a3a25..3c5f1a23704 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -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) ||
diff --git a/sql/item_sum.h b/sql/item_sum.h
index 04f95dfd778..62cb5974388 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -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);}
};