summaryrefslogtreecommitdiff
path: root/sql/item_sum.cc
diff options
context:
space:
mode:
authorJorgen Loland <jorgen.loland@sun.com>2010-01-04 10:39:42 +0100
committerJorgen Loland <jorgen.loland@sun.com>2010-01-04 10:39:42 +0100
commit3dab08f157b33a248dee7037b7a42eb9c06798f6 (patch)
treea7fd5e0782b27e66d491823b2497fdd9195fbf6c /sql/item_sum.cc
parent8050affe244bd3477f128e0f04b3b8fb3af8cbd4 (diff)
downloadmariadb-git-3dab08f157b33a248dee7037b7a42eb9c06798f6.tar.gz
Bug#48920: COUNT DISTINCT returns 1 for NULL values when in a
subquery in the select list When a dependent subquery with count(distinct <col>) was evaluated multiple times, the Distinct_Aggregator was reused. However, the Aggregator was not reset, so when the subquery was evaluated for the next record in the outer select, old dependent info was used. The fix is to clear() the existing aggregator in Item_sum::set_aggregator(). This ensures that the aggregator is reevaluated with the new dependent information.
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r--sql/item_sum.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index c33088e0276..a61c5d59d67 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -578,7 +578,14 @@ int Item_sum::set_aggregator(Aggregator::Aggregator_type aggregator)
{
if (aggr)
{
+ /*
+ Dependent subselects may be executed multiple times, making
+ set_aggregator to be called multiple times. The aggregator type
+ will be the same, but it needs to be reset so that it is
+ reevaluated with the new dependent data.
+ */
DBUG_ASSERT(aggregator == aggr->Aggrtype());
+ aggr->clear();
return FALSE;
}
switch (aggregator)