2019-06-13 14:04:38 +00:00
|
|
|
DROP TABLE IF EXISTS codecTest;
|
|
|
|
|
|
|
|
CREATE TABLE codecTest (
|
|
|
|
key UInt64,
|
|
|
|
ref_valueU64 UInt64,
|
|
|
|
ref_valueU32 UInt32,
|
|
|
|
ref_valueU16 UInt16,
|
|
|
|
ref_valueU8 UInt8,
|
|
|
|
ref_valueI64 Int64,
|
|
|
|
ref_valueI32 Int32,
|
|
|
|
ref_valueI16 Int16,
|
|
|
|
ref_valueI8 Int8,
|
|
|
|
ref_valueDT DateTime,
|
|
|
|
ref_valueD Date,
|
|
|
|
valueU64 UInt64 CODEC(DoubleDelta),
|
|
|
|
valueU32 UInt32 CODEC(DoubleDelta),
|
|
|
|
valueU16 UInt16 CODEC(DoubleDelta),
|
|
|
|
valueU8 UInt8 CODEC(DoubleDelta),
|
|
|
|
valueI64 Int64 CODEC(DoubleDelta),
|
|
|
|
valueI32 Int32 CODEC(DoubleDelta),
|
|
|
|
valueI16 Int16 CODEC(DoubleDelta),
|
|
|
|
valueI8 Int8 CODEC(DoubleDelta),
|
|
|
|
valueDT DateTime CODEC(DoubleDelta),
|
|
|
|
valueD Date CODEC(DoubleDelta)
|
2021-05-05 22:09:08 +00:00
|
|
|
) Engine = MergeTree ORDER BY key SETTINGS min_bytes_for_wide_part = 0;
|
2019-06-13 14:04:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- checking for overflow
|
|
|
|
INSERT INTO codecTest (key, ref_valueU64, valueU64, ref_valueI64, valueI64)
|
2021-05-05 22:03:27 +00:00
|
|
|
VALUES (1, 18446744073709551615, 18446744073709551615, 9223372036854775807, 9223372036854775807), (2, 0, 0, -9223372036854775808, -9223372036854775808), (3, 18446744073709551615, 18446744073709551615, 9223372036854775807, 9223372036854775807);
|
2019-06-13 14:04:38 +00:00
|
|
|
|
|
|
|
-- n^3 covers all double delta storage cases, from small difference between neighbouref_values (stride) to big.
|
|
|
|
INSERT INTO codecTest (key, ref_valueU64, valueU64, ref_valueU32, valueU32, ref_valueU16, valueU16, ref_valueU8, valueU8, ref_valueI64, valueI64, ref_valueI32, valueI32, ref_valueI16, valueI16, ref_valueI8, valueI8, ref_valueDT, valueDT, ref_valueD, valueD)
|
2021-05-05 22:03:27 +00:00
|
|
|
SELECT number as n, n * n * n as v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, toDateTime(v), toDateTime(v), toDate(v), toDate(v)
|
|
|
|
FROM system.numbers LIMIT 101, 1000;
|
2019-06-13 14:04:38 +00:00
|
|
|
|
|
|
|
-- best case - constant stride
|
|
|
|
INSERT INTO codecTest (key, ref_valueU64, valueU64, ref_valueU32, valueU32, ref_valueU16, valueU16, ref_valueU8, valueU8, ref_valueI64, valueI64, ref_valueI32, valueI32, ref_valueI16, valueI16, ref_valueI8, valueI8, ref_valueDT, valueDT, ref_valueD, valueD)
|
2021-05-05 22:03:27 +00:00
|
|
|
SELECT number as n, n as v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, toDateTime(v), toDateTime(v), toDate(v), toDate(v)
|
|
|
|
FROM system.numbers LIMIT 2001, 1000;
|
2019-06-13 14:04:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- worst case - random stride
|
|
|
|
INSERT INTO codecTest (key, ref_valueU64, valueU64, ref_valueU32, valueU32, ref_valueU16, valueU16, ref_valueU8, valueU8, ref_valueI64, valueI64, ref_valueI32, valueI32, ref_valueI16, valueI16, ref_valueI8, valueI8, ref_valueDT, valueDT, ref_valueD, valueD)
|
2021-05-05 22:03:27 +00:00
|
|
|
SELECT number as n, n + (rand64() - 9223372036854775807)/1000 as v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, toDateTime(v), toDateTime(v), toDate(v), toDate(v)
|
|
|
|
FROM system.numbers LIMIT 3001, 1000;
|
2019-06-13 14:04:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
SELECT 'U64';
|
|
|
|
SELECT
|
2021-05-05 22:03:27 +00:00
|
|
|
key,
|
|
|
|
ref_valueU64, valueU64, ref_valueU64 - valueU64 as dU64
|
2019-06-13 14:04:38 +00:00
|
|
|
FROM codecTest
|
|
|
|
WHERE
|
2021-05-05 22:03:27 +00:00
|
|
|
dU64 != 0
|
2019-06-13 14:04:38 +00:00
|
|
|
LIMIT 10;
|
|
|
|
|
|
|
|
|
|
|
|
SELECT 'U32';
|
|
|
|
SELECT
|
2021-05-05 22:03:27 +00:00
|
|
|
key,
|
|
|
|
ref_valueU32, valueU32, ref_valueU32 - valueU32 as dU32
|
2019-06-13 14:04:38 +00:00
|
|
|
FROM codecTest
|
|
|
|
WHERE
|
2021-05-05 22:03:27 +00:00
|
|
|
dU32 != 0
|
2019-06-13 14:04:38 +00:00
|
|
|
LIMIT 10;
|
|
|
|
|
|
|
|
|
|
|
|
SELECT 'U16';
|
|
|
|
SELECT
|
2021-05-05 22:03:27 +00:00
|
|
|
key,
|
|
|
|
ref_valueU16, valueU16, ref_valueU16 - valueU16 as dU16
|
2019-06-13 14:04:38 +00:00
|
|
|
FROM codecTest
|
|
|
|
WHERE
|
2021-05-05 22:03:27 +00:00
|
|
|
dU16 != 0
|
2019-06-13 14:04:38 +00:00
|
|
|
LIMIT 10;
|
|
|
|
|
|
|
|
|
|
|
|
SELECT 'U8';
|
|
|
|
SELECT
|
2021-05-05 22:03:27 +00:00
|
|
|
key,
|
|
|
|
ref_valueU8, valueU8, ref_valueU8 - valueU8 as dU8
|
2019-06-13 14:04:38 +00:00
|
|
|
FROM codecTest
|
|
|
|
WHERE
|
2021-05-05 22:03:27 +00:00
|
|
|
dU8 != 0
|
2019-06-13 14:04:38 +00:00
|
|
|
LIMIT 10;
|
|
|
|
|
|
|
|
|
|
|
|
SELECT 'I64';
|
|
|
|
SELECT
|
2021-05-05 22:03:27 +00:00
|
|
|
key,
|
|
|
|
ref_valueI64, valueI64, ref_valueI64 - valueI64 as dI64
|
2019-06-13 14:04:38 +00:00
|
|
|
FROM codecTest
|
|
|
|
WHERE
|
2021-05-05 22:03:27 +00:00
|
|
|
dI64 != 0
|
2019-06-13 14:04:38 +00:00
|
|
|
LIMIT 10;
|
|
|
|
|
|
|
|
|
|
|
|
SELECT 'I32';
|
|
|
|
SELECT
|
2021-05-05 22:03:27 +00:00
|
|
|
key,
|
|
|
|
ref_valueI32, valueI32, ref_valueI32 - valueI32 as dI32
|
2019-06-13 14:04:38 +00:00
|
|
|
FROM codecTest
|
|
|
|
WHERE
|
2021-05-05 22:03:27 +00:00
|
|
|
dI32 != 0
|
2019-06-13 14:04:38 +00:00
|
|
|
LIMIT 10;
|
|
|
|
|
|
|
|
|
|
|
|
SELECT 'I16';
|
|
|
|
SELECT
|
2021-05-05 22:03:27 +00:00
|
|
|
key,
|
|
|
|
ref_valueI16, valueI16, ref_valueI16 - valueI16 as dI16
|
2019-06-13 14:04:38 +00:00
|
|
|
FROM codecTest
|
|
|
|
WHERE
|
2021-05-05 22:03:27 +00:00
|
|
|
dI16 != 0
|
2019-06-13 14:04:38 +00:00
|
|
|
LIMIT 10;
|
|
|
|
|
|
|
|
|
|
|
|
SELECT 'I8';
|
|
|
|
SELECT
|
2021-05-05 22:03:27 +00:00
|
|
|
key,
|
|
|
|
ref_valueI8, valueI8, ref_valueI8 - valueI8 as dI8
|
2019-06-13 14:04:38 +00:00
|
|
|
FROM codecTest
|
|
|
|
WHERE
|
2021-05-05 22:03:27 +00:00
|
|
|
dI8 != 0
|
2019-06-13 14:04:38 +00:00
|
|
|
LIMIT 10;
|
|
|
|
|
|
|
|
|
|
|
|
SELECT 'DT';
|
|
|
|
SELECT
|
2021-05-05 22:03:27 +00:00
|
|
|
key,
|
|
|
|
ref_valueDT, valueDT, ref_valueDT - valueDT as dDT
|
2019-06-13 14:04:38 +00:00
|
|
|
FROM codecTest
|
|
|
|
WHERE
|
2021-05-05 22:03:27 +00:00
|
|
|
dDT != 0
|
2019-06-13 14:04:38 +00:00
|
|
|
LIMIT 10;
|
|
|
|
|
|
|
|
|
|
|
|
SELECT 'D';
|
|
|
|
SELECT
|
2021-05-05 22:03:27 +00:00
|
|
|
key,
|
|
|
|
ref_valueD, valueD, ref_valueD - valueD as dD
|
2019-06-13 14:04:38 +00:00
|
|
|
FROM codecTest
|
|
|
|
WHERE
|
2021-05-05 22:03:27 +00:00
|
|
|
dD != 0
|
2019-06-13 14:04:38 +00:00
|
|
|
LIMIT 10;
|
|
|
|
|
2019-07-01 14:11:24 +00:00
|
|
|
SELECT 'Compression:';
|
|
|
|
SELECT
|
2021-05-05 22:03:27 +00:00
|
|
|
table, name, type,
|
|
|
|
compression_codec,
|
|
|
|
data_uncompressed_bytes u,
|
|
|
|
data_compressed_bytes c,
|
|
|
|
round(u/c,3) ratio
|
2019-07-01 14:11:24 +00:00
|
|
|
FROM system.columns
|
|
|
|
WHERE
|
2021-05-05 22:09:08 +00:00
|
|
|
table = 'codecTest'
|
|
|
|
AND database = currentDatabase()
|
2019-07-01 14:11:24 +00:00
|
|
|
AND
|
2021-05-05 22:03:27 +00:00
|
|
|
compression_codec != ''
|
2019-07-01 14:11:24 +00:00
|
|
|
AND
|
2021-05-05 22:03:27 +00:00
|
|
|
ratio <= 1
|
2019-07-01 14:11:24 +00:00
|
|
|
ORDER BY
|
2021-05-05 22:03:27 +00:00
|
|
|
table, name, type;
|
2019-06-13 14:04:38 +00:00
|
|
|
|
2020-02-11 18:05:08 +00:00
|
|
|
DROP TABLE IF EXISTS codecTest;
|