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 /mysql-test/t/subselect3.test | |
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 'mysql-test/t/subselect3.test')
-rw-r--r-- | mysql-test/t/subselect3.test | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/mysql-test/t/subselect3.test b/mysql-test/t/subselect3.test index fab0a462157..39c97941031 100644 --- a/mysql-test/t/subselect3.test +++ b/mysql-test/t/subselect3.test @@ -794,3 +794,50 @@ SHOW STATUS LIKE '%Handler_read_rnd_next'; DROP TABLE t1,t2; --echo End of 5.1 tests + +--echo # +--echo # BUG#48920: COUNT DISTINCT returns 1 for NULL values when in a subquery +--echo # in the select list +--echo # + +--echo +CREATE TABLE t1 ( + i int(11) DEFAULT NULL, + v varchar(1) DEFAULT NULL +); + +--echo +INSERT INTO t1 VALUES (8,'v'); +INSERT INTO t1 VALUES (9,'r'); +INSERT INTO t1 VALUES (NULL,'y'); + +--echo +CREATE TABLE t2 ( + i int(11) DEFAULT NULL, + v varchar(1) DEFAULT NULL, + KEY i_key (i) +); + +--echo +INSERT INTO t2 VALUES (NULL,'r'); +INSERT INTO t2 VALUES (0,'c'); +INSERT INTO t2 VALUES (0,'o'); +INSERT INTO t2 VALUES (2,'v'); +INSERT INTO t2 VALUES (7,'c'); + +--echo +SELECT i, v, (SELECT COUNT(DISTINCT i) + FROM t1 + WHERE v = t2.v) as subsel +FROM t2; + +--echo +EXPLAIN EXTENDED +SELECT i, v, (SELECT COUNT(DISTINCT i) + FROM t1 + WHERE v = t2.v) as subsel +FROM t2; + +DROP TABLE t1,t2; + +--echo End of 5.6 tests |