summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorunknown <konstantin@mysql.com>2005-03-15 03:46:19 +0300
committerunknown <konstantin@mysql.com>2005-03-15 03:46:19 +0300
commit897849e5d8802ebe6a42803cba72caa80cd23415 (patch)
tree7afe84de6147f4619865e4f759eb1d0ad2f376f8 /mysql-test
parentce4f43cb860e71a3d5e48773e305ff8e5e130872 (diff)
downloadmariadb-git-897849e5d8802ebe6a42803cba72caa80cd23415.tar.gz
WL#926 "AVG(DISTINCT) and other distincts", part 2 (out of 3): clean up
Item_sum_count_distinct, and deploy Unique for use with COUNT(DISTINCT) if there is no blob column in the list of DISTINCT arguments. mysql-test/r/count_distinct2.result: Test results fixed. mysql-test/r/func_group.result: Updated. mysql-test/r/sum_distinct.result: Updated. mysql-test/t/func_group.test: Add a test for COUNT(DISTINCT) and true varchar and case-insensitive collation. The table in the test contains only two distinct values. mysql-test/t/sum_distinct.test: Since now we support INSERT INTO t1 (a) SELECT a+1 FROM t1, shorten the test. Add a nominal test for AVG(DISTINCT) sql/item_sum.cc: Implementation of cleaned up Item_sum_count_distinct. Fixed a bug with COUNT(DISTINCT) and new VARCHAR and collations. Fixed a bug wiht AVG(DISTINCT) and wrong number of output digits after decimal point. sql/item_sum.h: Cleanup for Item_sum_count_distinct. Now if the list of distinct arguments doesn't contain a blob column, we always use Unique and merge-sort to find distinct values. sql/sql_class.h: Added a short-cut to find number of elements in Unique if all elements fit into memory.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/count_distinct2.result2
-rw-r--r--mysql-test/r/func_group.result7
-rw-r--r--mysql-test/r/sum_distinct.result98
-rw-r--r--mysql-test/t/func_group.test10
-rw-r--r--mysql-test/t/sum_distinct.test82
5 files changed, 91 insertions, 108 deletions
diff --git a/mysql-test/r/count_distinct2.result b/mysql-test/r/count_distinct2.result
index 131e3b325ec..b92665b5c56 100644
--- a/mysql-test/r/count_distinct2.result
+++ b/mysql-test/r/count_distinct2.result
@@ -116,7 +116,7 @@ count(distinct n)
5000
show status like 'Created_tmp_disk_tables';
Variable_name Value
-Created_tmp_disk_tables 1
+Created_tmp_disk_tables 0
drop table t1;
create table t1 (s text);
flush status;
diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result
index 46dba6cdfa9..81663cd9d66 100644
--- a/mysql-test/r/func_group.result
+++ b/mysql-test/r/func_group.result
@@ -881,3 +881,10 @@ SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6;
MAX(id)
NULL
DROP TABLE t1;
+CREATE TABLE t1 (a VARCHAR(400));
+INSERT INTO t1 (a) VALUES ("A"), ("a"), ("a "), ("a "),
+("B"), ("b"), ("b "), ("b ");
+SELECT COUNT(DISTINCT a) FROM t1;
+COUNT(DISTINCT a)
+2
+DROP TABLE t1;
diff --git a/mysql-test/r/sum_distinct.result b/mysql-test/r/sum_distinct.result
index 34242817a54..0591943e800 100644
--- a/mysql-test/r/sum_distinct.result
+++ b/mysql-test/r/sum_distinct.result
@@ -98,60 +98,60 @@ DROP TABLE t1;
CREATE TABLE t1 (id INTEGER);
CREATE TABLE t2 (id INTEGER);
INSERT INTO t1 (id) VALUES (1), (1), (1),(1);
-INSERT INTO t2 (id) SELECT id FROM t1;
-INSERT INTO t1 (id) SELECT id FROM t2;
+INSERT INTO t1 (id) SELECT id FROM t1;
/* 8 */
-INSERT INTO t1 (id) SELECT id FROM t2;
+INSERT INTO t1 (id) SELECT id FROM t1;
/* 12 */
-INSERT INTO t1 (id) SELECT id FROM t2;
+INSERT INTO t1 (id) SELECT id FROM t1;
/* 16 */
-INSERT INTO t1 (id) SELECT id FROM t2;
+INSERT INTO t1 (id) SELECT id FROM t1;
/* 20 */
-INSERT INTO t1 (id) SELECT id FROM t2;
+INSERT INTO t1 (id) SELECT id FROM t1;
/* 24 */
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+1 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+2 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+4 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+8 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+16 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+32 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+64 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+128 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+256 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+512 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+1024 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+2048 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+4096 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+8192 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
+INSERT INTO t1 SELECT id+1 FROM t1;
+INSERT INTO t1 SELECT id+2 FROM t1;
+INSERT INTO t1 SELECT id+4 FROM t1;
+INSERT INTO t1 SELECT id+8 FROM t1;
+INSERT INTO t1 SELECT id+16 FROM t1;
+INSERT INTO t1 SELECT id+32 FROM t1;
+INSERT INTO t1 SELECT id+64 FROM t1;
+INSERT INTO t1 SELECT id+128 FROM t1;
+INSERT INTO t1 SELECT id+256 FROM t1;
+INSERT INTO t1 SELECT id+512 FROM t1;
+SELECT AVG(DISTINCT id) FROM t1 GROUP BY id % 13;
+AVG(DISTINCT id)
+513.5000
+508.0000
+509.0000
+510.0000
+511.0000
+512.0000
+513.0000
+514.0000
+515.0000
+516.0000
+517.0000
+511.5000
+512.5000
+SELECT SUM(DISTINCT id)/COUNT(DISTINCT id) FROM t1 GROUP BY id % 13;
+SUM(DISTINCT id)/COUNT(DISTINCT id)
+513.50000
+508.00000
+509.00000
+510.00000
+511.00000
+512.00000
+513.00000
+514.00000
+515.00000
+516.00000
+517.00000
+511.50000
+512.50000
+INSERT INTO t1 SELECT id+1024 FROM t1;
+INSERT INTO t1 SELECT id+2048 FROM t1;
+INSERT INTO t1 SELECT id+4096 FROM t1;
+INSERT INTO t1 SELECT id+8192 FROM t1;
INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand();
SELECT SUM(DISTINCT id) sm FROM t1;
sm
diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test
index de9c7ff3ecb..0f03eae7e12 100644
--- a/mysql-test/t/func_group.test
+++ b/mysql-test/t/func_group.test
@@ -591,3 +591,13 @@ INSERT INTO t1 VALUES
(1,1,4), (2,2,1), (3,1,3), (4,2,1), (5,1,1);
SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6;
DROP TABLE t1;
+
+#
+# Test that new VARCHAR correctly works with COUNT(DISTINCT)
+#
+
+CREATE TABLE t1 (a VARCHAR(400));
+INSERT INTO t1 (a) VALUES ("A"), ("a"), ("a "), ("a "),
+ ("B"), ("b"), ("b "), ("b ");
+SELECT COUNT(DISTINCT a) FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/t/sum_distinct.test b/mysql-test/t/sum_distinct.test
index 964da9defa6..3b9f12354e8 100644
--- a/mysql-test/t/sum_distinct.test
+++ b/mysql-test/t/sum_distinct.test
@@ -103,64 +103,30 @@ CREATE TABLE t1 (id INTEGER);
CREATE TABLE t2 (id INTEGER);
INSERT INTO t1 (id) VALUES (1), (1), (1),(1);
-INSERT INTO t2 (id) SELECT id FROM t1;
-INSERT INTO t1 (id) SELECT id FROM t2; /* 8 */
-INSERT INTO t1 (id) SELECT id FROM t2; /* 12 */
-INSERT INTO t1 (id) SELECT id FROM t2; /* 16 */
-INSERT INTO t1 (id) SELECT id FROM t2; /* 20 */
-INSERT INTO t1 (id) SELECT id FROM t2; /* 24 */
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+1 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+2 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+4 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+8 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+16 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+32 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+64 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+128 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+256 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+512 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+1024 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+2048 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+4096 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-INSERT INTO t2 (id) SELECT id+8192 FROM t1;
-INSERT INTO t1 SELECT id FROM t2;
-DELETE FROM t2;
-#INSERT INTO t2 (id) SELECT id+16384 FROM t1;
-#INSERT INTO t1 SELECT id FROM t2;
-#DELETE FROM t2;
-#INSERT INTO t2 (id) SELECT id+32768 FROM t1;
-#INSERT INTO t1 SELECT id FROM t2;
-#DELETE FROM t2;
-#INSERT INTO t2 (id) SELECT id+65536 FROM t1;
-#INSERT INTO t1 SELECT id FROM t2;
-#DELETE FROM t2;
+INSERT INTO t1 (id) SELECT id FROM t1; /* 8 */
+INSERT INTO t1 (id) SELECT id FROM t1; /* 12 */
+INSERT INTO t1 (id) SELECT id FROM t1; /* 16 */
+INSERT INTO t1 (id) SELECT id FROM t1; /* 20 */
+INSERT INTO t1 (id) SELECT id FROM t1; /* 24 */
+INSERT INTO t1 SELECT id+1 FROM t1;
+INSERT INTO t1 SELECT id+2 FROM t1;
+INSERT INTO t1 SELECT id+4 FROM t1;
+INSERT INTO t1 SELECT id+8 FROM t1;
+INSERT INTO t1 SELECT id+16 FROM t1;
+INSERT INTO t1 SELECT id+32 FROM t1;
+INSERT INTO t1 SELECT id+64 FROM t1;
+INSERT INTO t1 SELECT id+128 FROM t1;
+INSERT INTO t1 SELECT id+256 FROM t1;
+INSERT INTO t1 SELECT id+512 FROM t1;
+
+# Just test that AVG(DISTINCT) is there
+SELECT AVG(DISTINCT id) FROM t1 GROUP BY id % 13;
+SELECT SUM(DISTINCT id)/COUNT(DISTINCT id) FROM t1 GROUP BY id % 13;
+
+INSERT INTO t1 SELECT id+1024 FROM t1;
+INSERT INTO t1 SELECT id+2048 FROM t1;
+INSERT INTO t1 SELECT id+4096 FROM t1;
+INSERT INTO t1 SELECT id+8192 FROM t1;
INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand();
# SELECT '++++++++++++++++++++++++++++++++++++++++++++++++++';