1
by brian
clean slate |
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;
|
|
6 |
/* 8 */
|
|
7 |
INSERT INTO t1 (id) SELECT id FROM t1;
|
|
8 |
/* 12 */
|
|
9 |
INSERT INTO t1 (id) SELECT id FROM t1;
|
|
10 |
/* 16 */
|
|
11 |
INSERT INTO t1 (id) SELECT id FROM t1;
|
|
12 |
/* 20 */
|
|
13 |
INSERT INTO t1 (id) SELECT id FROM t1;
|
|
14 |
/* 24 */
|
|
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;
|
|
26 |
AVG(DISTINCT id)
|
|
27 |
513.5000
|
|
28 |
508.0000
|
|
29 |
509.0000
|
|
30 |
510.0000
|
|
31 |
511.0000
|
|
32 |
512.0000
|
|
33 |
513.0000
|
|
34 |
514.0000
|
|
35 |
515.0000
|
|
36 |
516.0000
|
|
37 |
517.0000
|
|
38 |
511.5000
|
|
39 |
512.5000
|
|
40 |
SELECT SUM(DISTINCT id)/COUNT(DISTINCT id) FROM t1 GROUP BY id % 13;
|
|
41 |
SUM(DISTINCT id)/COUNT(DISTINCT id)
|
|
42 |
513.5000
|
|
43 |
508.0000
|
|
44 |
509.0000
|
|
45 |
510.0000
|
|
46 |
511.0000
|
|
47 |
512.0000
|
|
48 |
513.0000
|
|
49 |
514.0000
|
|
50 |
515.0000
|
|
51 |
516.0000
|
|
52 |
517.0000
|
|
53 |
511.5000
|
|
54 |
512.5000
|
|
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;
|
|
61 |
sm
|
|
62 |
134225920
|
|
63 |
SELECT SUM(DISTINCT id) sm FROM t2;
|
|
64 |
sm
|
|
65 |
134225920
|
|
66 |
SELECT SUM(DISTINCT id) sm FROM t1 group by id % 13;
|
|
67 |
sm
|
|
68 |
10327590
|
|
69 |
10328851
|
|
70 |
10330112
|
|
71 |
10331373
|
|
72 |
10332634
|
|
73 |
10317510
|
|
74 |
10318770
|
|
75 |
10320030
|
|
76 |
10321290
|
|
77 |
10322550
|
|
78 |
10323810
|
|
79 |
10325070
|
|
80 |
10326330
|
|
81 |
SET max_heap_table_size=16384;
|
|
82 |
SHOW variables LIKE 'max_heap_table_size';
|
|
83 |
Variable_name Value
|
|
84 |
max_heap_table_size 16384
|
|
85 |
SELECT SUM(DISTINCT id) sm FROM t1;
|
|
86 |
sm
|
|
87 |
134225920
|
|
88 |
SELECT SUM(DISTINCT id) sm FROM t2;
|
|
89 |
sm
|
|
90 |
134225920
|
|
91 |
SELECT SUM(DISTINCT id) sm FROM t1 GROUP BY id % 13;
|
|
92 |
sm
|
|
93 |
10327590
|
|
94 |
10328851
|
|
95 |
10330112
|
|
96 |
10331373
|
|
97 |
10332634
|
|
98 |
10317510
|
|
99 |
10318770
|
|
100 |
10320030
|
|
101 |
10321290
|
|
102 |
10322550
|
|
103 |
10323810
|
|
104 |
10325070
|
|
105 |
10326330
|
|
106 |
DROP TABLE t1;
|
|
107 |
DROP TABLE t2;
|