Add tests

This commit is contained in:
cangyin 2024-04-08 12:34:59 +08:00
parent cc5456c649
commit 603a52caa0
2 changed files with 140 additions and 0 deletions

View File

@ -0,0 +1,28 @@
ReplacingMergeTree
0 2
1 2
2 2
0 2
1 2
2 2
CollapsingMergeTree
0 2
1 2
2 2
0 2
1 2
2 2
VersionedCollapsingMergeTree
0 2
1 2
2 2
0 2
1 2
2 2
DEDUPLICATE ON MergeTree
0 1
1 1
2 1
0 1
1 1
2 1

View File

@ -0,0 +1,112 @@
SELECT 'ReplacingMergeTree';
DROP TABLE IF EXISTS tp;
CREATE TABLE tp
(
`type` Int32,
`eventcnt` UInt64,
PROJECTION p
(
SELECT type,sum(eventcnt)
GROUP BY type
)
)
ENGINE = ReplacingMergeTree
ORDER BY type;
INSERT INTO tp SELECT number%3, 1 FROM numbers(3);
INSERT INTO tp SELECT number%3, 2 FROM numbers(3);
OPTIMIZE TABLE tp FINAL;
SELECT type,sum(eventcnt) FROM tp GROUP BY type ORDER BY type
SETTINGS allow_experimental_projection_optimization = 0, force_optimize_projection = 0;
SELECT type,sum(eventcnt) FROM tp GROUP BY type ORDER BY type
SETTINGS allow_experimental_projection_optimization = 1, force_optimize_projection = 1;
SELECT 'CollapsingMergeTree';
DROP TABLE IF EXISTS tp;
CREATE TABLE tp
(
`type` Int32,
`eventcnt` UInt64,
`sign` Int8,
PROJECTION p
(
SELECT type,sum(eventcnt)
GROUP BY type
)
)
ENGINE = CollapsingMergeTree(sign)
ORDER BY type;
INSERT INTO tp SELECT number % 3, 1, 1 FROM numbers(3);
INSERT INTO tp SELECT number % 3, 1, -1 FROM numbers(3);
INSERT INTO tp SELECT number % 3, 2, 1 FROM numbers(3);
OPTIMIZE TABLE tp FINAL;
SELECT type,sum(eventcnt) FROM tp GROUP BY type ORDER BY type
SETTINGS allow_experimental_projection_optimization = 0, force_optimize_projection = 0;
SELECT type,sum(eventcnt) FROM tp GROUP BY type ORDER BY type
SETTINGS allow_experimental_projection_optimization = 1, force_optimize_projection = 1;
-- Actually we don't need to test all 3 engines Replacing/Collapsing/VersionedCollapsing,
-- Because they share the same logic of 'reduce number of rows during merges'
SELECT 'VersionedCollapsingMergeTree';
DROP TABLE IF EXISTS tp;
CREATE TABLE tp
(
`type` Int32,
`eventcnt` UInt64,
`sign` Int8,
`version` UInt8,
PROJECTION p
(
SELECT type,sum(eventcnt)
GROUP BY type
)
)
ENGINE = VersionedCollapsingMergeTree(sign,version)
ORDER BY type;
INSERT INTO tp SELECT number % 3, 1, -1, 0 FROM numbers(3);
INSERT INTO tp SELECT number % 3, 2, 1, 1 FROM numbers(3);
INSERT INTO tp SELECT number % 3, 1, 1, 0 FROM numbers(3);
OPTIMIZE TABLE tp FINAL;
SELECT type,sum(eventcnt) FROM tp GROUP BY type ORDER BY type
SETTINGS allow_experimental_projection_optimization = 0, force_optimize_projection = 0;
SELECT type,sum(eventcnt) FROM tp GROUP BY type ORDER BY type
SETTINGS allow_experimental_projection_optimization = 1, force_optimize_projection = 1;
SELECT 'DEDUPLICATE ON MergeTree';
DROP TABLE IF EXISTS tp;
CREATE TABLE tp
(
`type` Int32,
`eventcnt` UInt64,
PROJECTION p
(
SELECT type,sum(eventcnt)
GROUP BY type
)
)
ENGINE = MergeTree
ORDER BY type;
INSERT INTO tp SELECT number % 3, 1 FROM numbers(3);
INSERT INTO tp SELECT number % 3, 2 FROM numbers(3);
OPTIMIZE TABLE tp FINAL DEDUPLICATE BY type;
SELECT type,sum(eventcnt) FROM tp GROUP BY type ORDER BY type
SETTINGS allow_experimental_projection_optimization = 0, force_optimize_projection = 0;
SELECT type,sum(eventcnt) FROM tp GROUP BY type ORDER BY type
SETTINGS allow_experimental_projection_optimization = 1, force_optimize_projection = 1;