From b3230cc265ce456f3ec007deaac7d0f72d564075 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Mar 2006 12:20:25 +0300 Subject: [PATCH] Test case for BUG#15102 : select distinct returns empty result, select count distinct > 0 (correct) Reproduced in 5.0.16-nt. Tested to work in 5.0.20 mysql-test/r/group_min_max.result: Test case for BUG#15102 : select distinct returns empty result, select count distinct > 0 (correct) Reproduced in 5.0.16-nt. Tested to be fixed in 5.0.20 mysql-test/t/group_min_max.test: Test case for BUG#15102 : select distinct returns empty result, select count distinct > 0 (correct) Reproduced in 5.0.16-nt. Tested to be fixed in 5.0.20 --- mysql-test/r/group_min_max.result | 37 ++++++++++++++++++++++++++++++ mysql-test/t/group_min_max.test | 38 +++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/mysql-test/r/group_min_max.result b/mysql-test/r/group_min_max.result index b1703c51f4e..b889d031079 100644 --- a/mysql-test/r/group_min_max.result +++ b/mysql-test/r/group_min_max.result @@ -2070,3 +2070,40 @@ SELECT a FROM t1 WHERE a LIKE 'B%' GROUP BY a; a BB DROP TABLE t1; +CREATE TABLE t1 ( +a int(11) NOT NULL DEFAULT '0', +b varchar(16) COLLATE latin1_general_ci NOT NULL DEFAULT '', +PRIMARY KEY (a,b) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; +CREATE PROCEDURE a(x INT) +BEGIN +DECLARE rnd INT; +DECLARE cnt INT; +WHILE x > 0 DO +SET rnd= x % 100; +SET cnt = (SELECT COUNT(*) FROM t1 WHERE a = rnd); +INSERT INTO t1(a,b) VALUES (rnd, CAST(cnt AS CHAR)); +SET x= x - 1; +END WHILE; +END| +CALL a(1000); +SELECT a FROM t1 WHERE a=0; +a +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +SELECT DISTINCT a FROM t1 WHERE a=0; +a +0 +SELECT COUNT(DISTINCT a) FROM t1 WHERE a=0; +COUNT(DISTINCT a) +1 +DROP TABLE t1; +DROP PROCEDURE a; diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test index 8dc55532bbf..0f0a632ff67 100644 --- a/mysql-test/t/group_min_max.test +++ b/mysql-test/t/group_min_max.test @@ -736,3 +736,41 @@ SELECT DISTINCT a FROM t1 WHERE a LIKE 'B%'; SELECT a FROM t1 WHERE a LIKE 'B%' GROUP BY a; DROP TABLE t1; + + +# +# Bug #15102: select distinct returns empty result, select count +# distinct > 0 (correct) +# + +CREATE TABLE t1 ( + a int(11) NOT NULL DEFAULT '0', + b varchar(16) COLLATE latin1_general_ci NOT NULL DEFAULT '', + PRIMARY KEY (a,b) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; + +delimiter |; + +CREATE PROCEDURE a(x INT) +BEGIN + DECLARE rnd INT; + DECLARE cnt INT; + + WHILE x > 0 DO + SET rnd= x % 100; + SET cnt = (SELECT COUNT(*) FROM t1 WHERE a = rnd); + INSERT INTO t1(a,b) VALUES (rnd, CAST(cnt AS CHAR)); + SET x= x - 1; + END WHILE; +END| + +DELIMITER ;| + +CALL a(1000); + +SELECT a FROM t1 WHERE a=0; +SELECT DISTINCT a FROM t1 WHERE a=0; +SELECT COUNT(DISTINCT a) FROM t1 WHERE a=0; + +DROP TABLE t1; +DROP PROCEDURE a;