Last active
February 10, 2023 04:54
-
-
Save den-crane/dcec8056ccd9f129f401817bc8036d0e to your computer and use it in GitHub Desktop.
AggregatingMergeTree + projection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table test ( | |
A Int64, | |
B String, | |
SomeID AggregateFunction(uniq, Int64), | |
projection p1 (select B, uniqMergeState(SomeID) group by B) | |
) | |
Engine=AggregatingMergeTree order by (A, B); | |
insert into test select number A, number%3 B, uniqState(toInt64(rand64())) from numbers(1e7) group by A,B; | |
select B, finalizeAggregation(uniqMergeState(SomeID)) from test group by B | |
settings allow_experimental_projection_optimization = 0; | |
┌─B─┬─finalizeAggregation(uniqMergeState(SomeID))─┐ | |
│ 2 │ 3315471 │ | |
│ 1 │ 3329550 │ | |
│ 0 │ 3325098 │ | |
└───┴─────────────────────────────────────────────┘ | |
3 rows in set. Elapsed: 0.364 sec. Processed 10.00 million rows, 1.46 GB (27.49 million rows/s., 4.00 GB/s.) | |
select B, finalizeAggregation(uniqMergeState(SomeID)) from test group by B; | |
┌─B─┬─finalizeAggregation(uniqMergeState(SomeID))─┐ | |
│ 1 │ 3329550 │ | |
│ 0 │ 3325098 │ | |
│ 2 │ 3315471 │ | |
└───┴─────────────────────────────────────────────┘ | |
3 rows in set. Elapsed: 0.014 sec. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment