Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projection size after materialize projection #31669

Closed
den-crane opened this issue Nov 23, 2021 · 0 comments · Fixed by #31885
Closed

Projection size after materialize projection #31669

den-crane opened this issue Nov 23, 2021 · 0 comments · Fixed by #31885

Comments

@den-crane
Copy link
Contributor

den-crane commented Nov 23, 2021

alter table z materialize projection builds a projection with the size is much bigger than the size after insertion or merge.

create table z(pk Int64, d Date, id UInt64, c UInt64) Engine=MergeTree partition by d order by pk;

insert into z  select number, today(), intDiv (number, 1000000), 1 from numbers(100000000);
optimize table z final;

alter table z add projection pp (select id, sum(c) group by id);
alter table z materialize projection pp settings mutations_sync=1;

insert into z  select number, today()+1, intDiv (number, 1000000), 1 from numbers(100000000);

SELECT
    database,
    table,
    name,
    partition,
    formatReadableSize(sum(data_compressed_bytes) AS size) AS compressed,
    formatReadableSize(sum(data_uncompressed_bytes) AS usize) AS uncompressed,
    round(usize / size, 2) AS compr_rate,
    sum(rows) AS rows,
    count() AS part_count
FROM system.projection_parts
WHERE (table = 'z') AND active
GROUP BY
    database,
    table,
    name,
    partition
ORDER BY size DESC;

┌─database─┬─table─┬─name─┬─partition──┬─compressed─┬─uncompressed─┬─compr_rate─┬─rows─┬─part_count─┐
│ dw       │ z     │ pp   │ 2021-11-232.22 KiB   │ 28.80 KiB    │      12.97184311843 rows after materialize
│ dw       │ z     │ pp   │ 2021-11-24820.00 B   │ 1.63 KiB     │       2.031045104 rows after insert
└──────────┴───────┴──────┴────────────┴────────────┴──────────────┴────────────┴──────┴────────────┘

optimize table z final;

┌─database─┬─table─┬─name─┬─partition──┬─compressed─┬─uncompressed─┬─compr_rate─┬─rows─┬─part_count─┐
│ dw       │ z     │ pp   │ 2021-11-23475.00 B   │ 1.56 KiB     │       3.371001 │
│ dw       │ z     │ pp   │ 2021-11-24475.00 B   │ 1.56 KiB     │       3.371001 │
└──────────┴───────┴──────┴────────────┴────────────┴──────────────┴────────────┴──────┴────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants