1
DROP TABLE IF EXISTS t1, t2;
2
CREATE TABLE t1 (id INTEGER);
3
CREATE TABLE t2 (id INTEGER);
4
INSERT INTO t1 (id) VALUES (1), (1), (1),(1);
5
INSERT INTO t1 (id) SELECT id FROM t1;
7
INSERT INTO t1 (id) SELECT id FROM t1;
9
INSERT INTO t1 (id) SELECT id FROM t1;
11
INSERT INTO t1 (id) SELECT id FROM t1;
13
INSERT INTO t1 (id) SELECT id FROM t1;
15
INSERT INTO t1 SELECT id+1 FROM t1;
16
INSERT INTO t1 SELECT id+2 FROM t1;
17
INSERT INTO t1 SELECT id+4 FROM t1;
18
INSERT INTO t1 SELECT id+8 FROM t1;
19
INSERT INTO t1 SELECT id+16 FROM t1;
20
INSERT INTO t1 SELECT id+32 FROM t1;
21
INSERT INTO t1 SELECT id+64 FROM t1;
22
INSERT INTO t1 SELECT id+128 FROM t1;
23
INSERT INTO t1 SELECT id+256 FROM t1;
24
INSERT INTO t1 SELECT id+512 FROM t1;
25
SELECT AVG(DISTINCT id) FROM t1 GROUP BY id % 13;
40
SELECT SUM(DISTINCT id)/COUNT(DISTINCT id) FROM t1 GROUP BY id % 13;
41
SUM(DISTINCT id)/COUNT(DISTINCT id)
55
INSERT INTO t1 SELECT id+1024 FROM t1;
56
INSERT INTO t1 SELECT id+2048 FROM t1;
57
INSERT INTO t1 SELECT id+4096 FROM t1;
58
INSERT INTO t1 SELECT id+8192 FROM t1;
59
INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand();
60
SELECT SUM(DISTINCT id) sm FROM t1;
63
SELECT SUM(DISTINCT id) sm FROM t2;
66
SELECT SUM(DISTINCT id) sm FROM t1 group by id % 13;
81
SET max_heap_table_size=16384;
82
SHOW variables LIKE 'max_heap_table_size';
84
max_heap_table_size 16384
85
SELECT SUM(DISTINCT id) sm FROM t1;
88
SELECT SUM(DISTINCT id) sm FROM t2;
91
SELECT SUM(DISTINCT id) sm FROM t1 GROUP BY id % 13;