Skip to content

Instantly share code, notes, and snippets.

@den-crane
Created February 14, 2023 19:01
Show Gist options
  • Save den-crane/9bb45d391313cf5580c050dd83bf5764 to your computer and use it in GitHub Desktop.
Save den-crane/9bb45d391313cf5580c050dd83bf5764 to your computer and use it in GitHub Desktop.
primary key is loaded on Clickhouse start
create table idx( A Int64, D Date) Engine=MergeTree order by A partition by D;
insert into idx select number, today() from numbers(1e8);
insert into idx select number, today()-1 from numbers(1e8);
select sum(primary_key_bytes_in_memory), sum(primary_key_bytes_in_memory_allocated)
from system.parts where table = 'idx' and active;
┌─sum(primary_key_bytes_in_memory)─┬─sum(primary_key_bytes_in_memory_allocated)─┐
│ 195360 │ 264192 │
└──────────────────────────────────┴────────────────────────────────────────────┘
detach table idx;
attach table idx;
select sum(primary_key_bytes_in_memory), sum(primary_key_bytes_in_memory_allocated)
from system.parts where table = 'idx' and active;
┌─sum(primary_key_bytes_in_memory)─┬─sum(primary_key_bytes_in_memory_allocated)─┐
│ 195360 │ 264192 │
└──────────────────────────────────┴────────────────────────────────────────────┘
systemctl restart clickhouse-server
select sum(primary_key_bytes_in_memory), sum(primary_key_bytes_in_memory_allocated)
from system.parts where table = 'idx' and active;
┌─sum(primary_key_bytes_in_memory)─┬─sum(primary_key_bytes_in_memory_allocated)─┐
│ 195360 │ 264192 │
└──────────────────────────────────┴────────────────────────────────────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment