How to change order of composed primary key in clickhouse efficiently

2.1k Views Asked by At

I have a table with schema

CREATE TABLE traffic ( date Date, val1 UInt64, 'val2' UInt64 ... ) ENGINE = ReplicatedMergeTree(date, (val1, val2), 8192);

the partition key is date here. I want to change the order from (val1, val2) to (val2, val1)

I only way i know is rename this table to someting(traffic_temp), create table with name 'trafic' and ordering (val2, val1) and copy the data from temp to traffic and then delete the temp table.

But the dataset is huge, is there any better way to do it??

1

There are 1 best solutions below

5
Denny Crane On

No other way. Only insert select.

You can use clickhouse-copier but it does the same insert select