~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Various tests for SUM(DISTINCT ...)
3
#
4
5
--source include/big_test.inc
6
--disable_warnings
7
DROP TABLE IF EXISTS t1, t2;
8
--enable_warnings
9
10
#
11
# Test the case when distinct values doesn't fit in memory and 
12
# filesort is used (see uniques.cc:merge_walk)
13
#
14
15
CREATE TABLE t1 (id INTEGER);
16
CREATE TABLE t2 (id INTEGER);
17
18
INSERT INTO t1 (id) VALUES (1), (1), (1),(1);
19
INSERT INTO t1 (id) SELECT id FROM t1; /* 8 */
20
INSERT INTO t1 (id) SELECT id FROM t1; /* 12 */
21
INSERT INTO t1 (id) SELECT id FROM t1; /* 16 */
22
INSERT INTO t1 (id) SELECT id FROM t1; /* 20 */
23
INSERT INTO t1 (id) SELECT id FROM t1; /* 24 */
24
INSERT INTO t1 SELECT id+1 FROM t1;
25
INSERT INTO t1 SELECT id+2 FROM t1;
26
INSERT INTO t1 SELECT id+4 FROM t1;
27
INSERT INTO t1 SELECT id+8 FROM t1;
28
INSERT INTO t1 SELECT id+16 FROM t1;
29
INSERT INTO t1 SELECT id+32 FROM t1;
30
INSERT INTO t1 SELECT id+64 FROM t1;
31
INSERT INTO t1 SELECT id+128 FROM t1;
32
INSERT INTO t1 SELECT id+256 FROM t1;
33
INSERT INTO t1 SELECT id+512 FROM t1;
34
35
# Just test that AVG(DISTINCT) is there
36
SELECT AVG(DISTINCT id) FROM t1 GROUP BY id % 13;
37
SELECT SUM(DISTINCT id)/COUNT(DISTINCT id) FROM t1 GROUP BY id % 13;
38
39
INSERT INTO t1 SELECT id+1024 FROM t1;
40
INSERT INTO t1 SELECT id+2048 FROM t1;
41
INSERT INTO t1 SELECT id+4096 FROM t1;
42
INSERT INTO t1 SELECT id+8192 FROM t1;
43
INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand();
44
45
# SELECT '++++++++++++++++++++++++++++++++++++++++++++++++++';
46
47
SELECT SUM(DISTINCT id) sm FROM t1;
48
SELECT SUM(DISTINCT id) sm FROM t2;
49
SELECT SUM(DISTINCT id) sm FROM t1 group by id % 13;
50
51
# this limit for max_heap_table_size is set to force testing the case, when
52
# all distinct sum values can not fit in memory and must be stored in a
53
# temporary table
54
55
SET max_heap_table_size=16384;
56
57
# to check that max_heap_table_size was actually set (hard limit for minimum
58
# max_heap_table_size is set in mysqld.cc):
59
60
SHOW variables LIKE 'max_heap_table_size';
61
62
SELECT SUM(DISTINCT id) sm FROM t1;
63
SELECT SUM(DISTINCT id) sm FROM t2;
64
SELECT SUM(DISTINCT id) sm FROM t1 GROUP BY id % 13;
65
66
DROP TABLE t1;
67
DROP TABLE t2;