summaryrefslogtreecommitdiff
path: root/sql/item_sum.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2013-03-31 15:18:55 -0700
committerIgor Babaev <igor@askmonty.org>2013-03-31 15:18:55 -0700
commit0f3f93532bf19464c88b67e502fccec293f91d39 (patch)
tree7f7a6b3e361e48865ae61c5aac85d1d6cdf31ee3 /sql/item_sum.cc
parent993ea79f2df42292eceeee394e8ece9f4a3f6cf2 (diff)
parent599a1384af7d38e4319bd6258c6954750f5b9ba4 (diff)
downloadmariadb-git-0f3f93532bf19464c88b67e502fccec293f91d39.tar.gz
Merge 5.5->10.0-base
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r--sql/item_sum.cc33
1 files changed, 31 insertions, 2 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 9410a12f21b..03afd1a4365 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -735,7 +735,15 @@ int simple_raw_key_cmp(void* arg, const void* key1, const void* key2)
}
-int item_sum_distinct_walk(void *element, element_count num_of_dups,
+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)
{
return ((Aggregator_distinct*) (item))->unique_walk_function(element);
@@ -1105,7 +1113,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 */
@@ -1482,6 +1495,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)