2021-04-03 02:40:30 +00:00
|
|
|
-- { echo }
|
|
|
|
|
2021-04-03 00:04:48 +00:00
|
|
|
DROP TABLE IF EXISTS t_sparse;
|
2021-04-03 02:40:30 +00:00
|
|
|
DROP TABLE IF EXISTS t_sparse_1;
|
2021-04-03 00:04:48 +00:00
|
|
|
|
|
|
|
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 00:04:48 +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;
|
|
|
|
|
|
|
|
SELECT * FROM t_sparse WHERE u != 0 ORDER BY id;
|
|
|
|
SELECT * FROM t_sparse WHERE s != '' ORDER BY id;
|
|
|
|
SELECT * FROM t_sparse WHERE arr1 != [] ORDER BY id;
|
|
|
|
SELECT * FROM t_sparse WHERE arr2 != [] ORDER BY id;
|
|
|
|
|
|
|
|
SELECT sum(u) FROM t_sparse;
|
2022-09-29 19:26:52 +00:00
|
|
|
SELECT id % 7, sum(u) FROM t_sparse GROUP BY id % 7 ORDER BY id % 7;
|
2021-04-03 00:04:48 +00:00
|
|
|
|
|
|
|
SELECT arrayFilter(x -> x % 2 = 1, arr2) FROM t_sparse WHERE arr2 != [] LIMIT 5;
|
|
|
|
|
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;
|
|
|
|
SELECT * FROM t_sparse_1 ORDER BY v DESC, id;
|
2021-06-07 15:34:22 +00:00
|
|
|
SELECT * FROM t_sparse_1 ORDER BY v, id LIMIT 5;
|
|
|
|
SELECT * FROM t_sparse_1 ORDER BY v DESC, id LIMIT 5;
|
2021-04-03 02:40:30 +00:00
|
|
|
|
2021-04-03 00:04:48 +00:00
|
|
|
DROP TABLE t_sparse;
|
2021-04-03 02:40:30 +00:00
|
|
|
DROP TABLE t_sparse_1;
|