summaryrefslogtreecommitdiff
path: root/sql/item_sum.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2013-03-27 22:22:52 -0700
committerIgor Babaev <igor@askmonty.org>2013-03-27 22:22:52 -0700
commita2c3d7d371b51f0a41dd1bbf834f033f62db18b3 (patch)
tree83b40c35d0aa39ddbdede32d82a4e294605f9365 /sql/item_sum.cc
parent6599fd3e9c23a8957a63146cbe6a0ffc4c292a3d (diff)
parent323fdd7ac6e6541a6cc3ab7c48e330805c67d4f3 (diff)
downloadmariadb-git-a2c3d7d371b51f0a41dd1bbf834f033f62db18b3.tar.gz
Merge
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r--sql/item_sum.cc31
1 files changed, 30 insertions, 1 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 224c6e7b857..e3cf440249b 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -719,6 +719,14 @@ static int simple_raw_key_cmp(void* arg, const void* key1, const void* key2)
}
+static int item_sum_distinct_walk_for_count(void *element,
+ element_count num_of_dups,
+ void *item)
+{
+ return ((Aggregator_distinct*) (item))->unique_walk_function_for_count(element);
+}
+
+
static int item_sum_distinct_walk(void *element, element_count num_of_dups,
void *item)
{
@@ -1089,7 +1097,12 @@ void Aggregator_distinct::endup()
{
/* go over the tree of distinct keys and calculate the aggregate value */
use_distinct_values= TRUE;
- tree->walk(table, item_sum_distinct_walk, (void*) this);
+ tree_walk_action func;
+ if (item_sum->sum_func() == Item_sum::COUNT_DISTINCT_FUNC)
+ func= item_sum_distinct_walk_for_count;
+ else
+ func= item_sum_distinct_walk;
+ tree->walk(table, func, (void*) this);
use_distinct_values= FALSE;
}
/* prevent consecutive recalculations */
@@ -1466,6 +1479,22 @@ bool Aggregator_distinct::unique_walk_function(void *element)
}
+/*
+ A variant of unique_walk_function() that is to be used with Item_sum_count.
+
+ COUNT is a special aggregate function: it doesn't need the values, it only
+ needs to count them. COUNT needs to know the values are not NULLs, but NULL
+ values are not put into the Unique, so we don't need to check for NULLs here.
+*/
+
+bool Aggregator_distinct::unique_walk_function_for_count(void *element)
+{
+ Item_sum_count *sum= (Item_sum_count *)item_sum;
+ sum->count++;
+ return 0;
+}
+
+
Aggregator_distinct::~Aggregator_distinct()
{
if (tree)