diff options
author | Jorgen Loland <jorgen.loland@sun.com> | 2010-01-04 10:39:42 +0100 |
---|---|---|
committer | Jorgen Loland <jorgen.loland@sun.com> | 2010-01-04 10:39:42 +0100 |
commit | 305f2e7f8a368cb1f04b75e3953a727f7c67e5ad (patch) | |
tree | a7fd5e0782b27e66d491823b2497fdd9195fbf6c /sql/item_sum.cc | |
parent | 1445cdaec842e125ab4b4afd578124098e258dff (diff) | |
download | mariadb-git-305f2e7f8a368cb1f04b75e3953a727f7c67e5ad.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.
mysql-test/r/subselect3.result:
Added test case for BUG#48920
mysql-test/t/subselect3.test:
Added test case for BUG#48920
sql/item_sum.cc:
If an aggregator exists when Item_sum::set_aggregator() is
called (i.e., set_aggregator is called in a dependent
subquery), the aggregator is reset so that the aggregator is
reevaluated with the dependent information from the outer
record being evaluated.
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r-- | sql/item_sum.cc | 7 |
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) |