2021-04-03 02:40:30 +00:00
|
|
|
-- { echo }
|
|
|
|
|
|
|
|
DROP TABLE IF EXISTS t_sparse;
|
|
|
|
DROP TABLE IF EXISTS t_sparse_1;
|
|
|
|
CREATE TABLE t_sparse (id UInt64, u UInt64, s String, arr1 Array(String), arr2 Array(UInt64))
|
|
|
|
ENGINE = MergeTree ORDER BY tuple()
|
2021-05-19 01:48:46 +00:00
|
|
|
SETTINGS ratio_of_defaults_for_sparse_serialization = 0.1;
|
2021-04-03 02:40:30 +00:00
|
|
|
INSERT INTO t_sparse SELECT
|
|
|
|
number,
|
|
|
|
if (number % 10 = 0, number, 0),
|
|
|
|
if (number % 5 = 0, toString(number), ''),
|
|
|
|
if (number % 7 = 0, arrayMap(x -> toString(x), range(number % 10)), []),
|
|
|
|
if (number % 12 = 0, range(number % 10), [])
|
|
|
|
FROM numbers (200);
|
|
|
|
SELECT column, serialization_kind FROM system.parts_columns
|
|
|
|
WHERE table = 't_sparse' AND database = currentDatabase()
|
|
|
|
ORDER BY column;
|
2021-05-14 20:29:48 +00:00
|
|
|
arr1 Default
|
|
|
|
arr2 Default
|
2021-04-03 00:04:48 +00:00
|
|
|
id Default
|
|
|
|
s Sparse
|
|
|
|
u Sparse
|
2021-04-03 02:40:30 +00:00
|
|
|
SELECT * FROM t_sparse WHERE u != 0 ORDER BY id;
|
2021-04-03 00:04:48 +00:00
|
|
|
10 10 10 [] []
|
|
|
|
20 20 20 [] []
|
|
|
|
30 30 30 [] []
|
|
|
|
40 40 40 [] []
|
|
|
|
50 50 50 [] []
|
|
|
|
60 60 60 [] []
|
|
|
|
70 70 70 [] []
|
|
|
|
80 80 80 [] []
|
|
|
|
90 90 90 [] []
|
|
|
|
100 100 100 [] []
|
|
|
|
110 110 110 [] []
|
|
|
|
120 120 120 [] []
|
|
|
|
130 130 130 [] []
|
|
|
|
140 140 140 [] []
|
|
|
|
150 150 150 [] []
|
|
|
|
160 160 160 [] []
|
|
|
|
170 170 170 [] []
|
|
|
|
180 180 180 [] []
|
|
|
|
190 190 190 [] []
|
2021-04-03 02:40:30 +00:00
|
|
|
SELECT * FROM t_sparse WHERE s != '' ORDER BY id;
|
2021-04-03 00:04:48 +00:00
|
|
|
0 0 0 [] []
|
|
|
|
5 0 5 [] []
|
|
|
|
10 10 10 [] []
|
|
|
|
15 0 15 [] []
|
|
|
|
20 20 20 [] []
|
|
|
|
25 0 25 [] []
|
|
|
|
30 30 30 [] []
|
|
|
|
35 0 35 ['0','1','2','3','4'] []
|
|
|
|
40 40 40 [] []
|
|
|
|
45 0 45 [] []
|
|
|
|
50 50 50 [] []
|
|
|
|
55 0 55 [] []
|
|
|
|
60 60 60 [] []
|
|
|
|
65 0 65 [] []
|
|
|
|
70 70 70 [] []
|
|
|
|
75 0 75 [] []
|
|
|
|
80 80 80 [] []
|
|
|
|
85 0 85 [] []
|
|
|
|
90 90 90 [] []
|
|
|
|
95 0 95 [] []
|
|
|
|
100 100 100 [] []
|
|
|
|
105 0 105 ['0','1','2','3','4'] []
|
|
|
|
110 110 110 [] []
|
|
|
|
115 0 115 [] []
|
|
|
|
120 120 120 [] []
|
|
|
|
125 0 125 [] []
|
|
|
|
130 130 130 [] []
|
|
|
|
135 0 135 [] []
|
|
|
|
140 140 140 [] []
|
|
|
|
145 0 145 [] []
|
|
|
|
150 150 150 [] []
|
|
|
|
155 0 155 [] []
|
|
|
|
160 160 160 [] []
|
|
|
|
165 0 165 [] []
|
|
|
|
170 170 170 [] []
|
|
|
|
175 0 175 ['0','1','2','3','4'] []
|
|
|
|
180 180 180 [] []
|
|
|
|
185 0 185 [] []
|
|
|
|
190 190 190 [] []
|
|
|
|
195 0 195 [] []
|
2021-04-03 02:40:30 +00:00
|
|
|
SELECT * FROM t_sparse WHERE arr1 != [] ORDER BY id;
|
2021-04-03 00:04:48 +00:00
|
|
|
7 0 ['0','1','2','3','4','5','6'] []
|
|
|
|
14 0 ['0','1','2','3'] []
|
|
|
|
21 0 ['0'] []
|
|
|
|
28 0 ['0','1','2','3','4','5','6','7'] []
|
|
|
|
35 0 35 ['0','1','2','3','4'] []
|
|
|
|
42 0 ['0','1'] []
|
|
|
|
49 0 ['0','1','2','3','4','5','6','7','8'] []
|
|
|
|
56 0 ['0','1','2','3','4','5'] []
|
|
|
|
63 0 ['0','1','2'] []
|
|
|
|
77 0 ['0','1','2','3','4','5','6'] []
|
|
|
|
84 0 ['0','1','2','3'] [0,1,2,3]
|
|
|
|
91 0 ['0'] []
|
|
|
|
98 0 ['0','1','2','3','4','5','6','7'] []
|
|
|
|
105 0 105 ['0','1','2','3','4'] []
|
|
|
|
112 0 ['0','1'] []
|
|
|
|
119 0 ['0','1','2','3','4','5','6','7','8'] []
|
|
|
|
126 0 ['0','1','2','3','4','5'] []
|
|
|
|
133 0 ['0','1','2'] []
|
|
|
|
147 0 ['0','1','2','3','4','5','6'] []
|
|
|
|
154 0 ['0','1','2','3'] []
|
|
|
|
161 0 ['0'] []
|
|
|
|
168 0 ['0','1','2','3','4','5','6','7'] [0,1,2,3,4,5,6,7]
|
|
|
|
175 0 175 ['0','1','2','3','4'] []
|
|
|
|
182 0 ['0','1'] []
|
|
|
|
189 0 ['0','1','2','3','4','5','6','7','8'] []
|
|
|
|
196 0 ['0','1','2','3','4','5'] []
|
2021-04-03 02:40:30 +00:00
|
|
|
SELECT * FROM t_sparse WHERE arr2 != [] ORDER BY id;
|
2021-04-03 00:04:48 +00:00
|
|
|
12 0 [] [0,1]
|
|
|
|
24 0 [] [0,1,2,3]
|
|
|
|
36 0 [] [0,1,2,3,4,5]
|
|
|
|
48 0 [] [0,1,2,3,4,5,6,7]
|
|
|
|
72 0 [] [0,1]
|
|
|
|
84 0 ['0','1','2','3'] [0,1,2,3]
|
|
|
|
96 0 [] [0,1,2,3,4,5]
|
|
|
|
108 0 [] [0,1,2,3,4,5,6,7]
|
|
|
|
132 0 [] [0,1]
|
|
|
|
144 0 [] [0,1,2,3]
|
|
|
|
156 0 [] [0,1,2,3,4,5]
|
|
|
|
168 0 ['0','1','2','3','4','5','6','7'] [0,1,2,3,4,5,6,7]
|
|
|
|
192 0 [] [0,1]
|
2021-04-03 02:40:30 +00:00
|
|
|
SELECT sum(u) FROM t_sparse;
|
2021-04-03 00:04:48 +00:00
|
|
|
1900
|
2021-04-03 02:40:30 +00:00
|
|
|
SELECT sum(u) FROM t_sparse GROUP BY id % 7;
|
2021-04-03 00:04:48 +00:00
|
|
|
210
|
|
|
|
360
|
|
|
|
300
|
|
|
|
240
|
|
|
|
190
|
|
|
|
330
|
|
|
|
270
|
2021-04-03 02:40:30 +00:00
|
|
|
SELECT arrayFilter(x -> x % 2 = 1, arr2) FROM t_sparse WHERE arr2 != [] LIMIT 5;
|
2021-04-03 00:04:48 +00:00
|
|
|
[1]
|
|
|
|
[1,3]
|
|
|
|
[1,3,5]
|
|
|
|
[1,3,5,7]
|
|
|
|
[1]
|
2021-04-03 02:40:30 +00:00
|
|
|
CREATE TABLE t_sparse_1 (id UInt64, v Int64)
|
|
|
|
ENGINE = MergeTree ORDER BY tuple()
|
2021-05-19 01:48:46 +00:00
|
|
|
SETTINGS ratio_of_defaults_for_sparse_serialization = 0;
|
2021-04-03 02:40:30 +00:00
|
|
|
INSERT INTO t_sparse_1 VALUES (1, 6), (2, 1), (3, 0), (4, -1), (5, 0), (6, 0), (7, -2), (8, 0), (9, 0), (10, 4), (11, 0);
|
2022-02-02 21:51:19 +00:00
|
|
|
SELECT * FROM t_sparse_1 ORDER BY v, id;
|
2021-04-03 02:40:30 +00:00
|
|
|
7 -2
|
|
|
|
4 -1
|
|
|
|
3 0
|
|
|
|
5 0
|
|
|
|
6 0
|
|
|
|
8 0
|
|
|
|
9 0
|
|
|
|
11 0
|
|
|
|
2 1
|
|
|
|
10 4
|
|
|
|
1 6
|
2022-02-02 21:51:19 +00:00
|
|
|
SELECT * FROM t_sparse_1 ORDER BY v DESC, id;
|
2021-04-03 02:40:30 +00:00
|
|
|
1 6
|
|
|
|
10 4
|
|
|
|
2 1
|
|
|
|
3 0
|
|
|
|
5 0
|
|
|
|
6 0
|
|
|
|
8 0
|
|
|
|
9 0
|
|
|
|
11 0
|
|
|
|
4 -1
|
|
|
|
7 -2
|
2021-06-07 15:34:22 +00:00
|
|
|
SELECT * FROM t_sparse_1 ORDER BY v, id LIMIT 5;
|
2021-04-03 02:40:30 +00:00
|
|
|
7 -2
|
|
|
|
4 -1
|
|
|
|
3 0
|
|
|
|
5 0
|
|
|
|
6 0
|
2021-06-07 15:34:22 +00:00
|
|
|
SELECT * FROM t_sparse_1 ORDER BY v DESC, id LIMIT 5;
|
2021-04-03 02:40:30 +00:00
|
|
|
1 6
|
|
|
|
10 4
|
|
|
|
2 1
|
|
|
|
3 0
|
|
|
|
5 0
|
|
|
|
DROP TABLE t_sparse;
|
|
|
|
DROP TABLE t_sparse_1;
|