Clickhouse: ALTER of key column column_name must be metadata-only

Created on 13 Jun 2019  路  7Comments  路  Source: ClickHouse/ClickHouse

Given this table

CREATE TABLE IF NOT EXISTS table1 (
    column1        DateTime,
    column2        UInt32,
    column3        String,
    packets        AggregateFunction(sum, UInt32)
)
ENGINE = AggregatingMergeTree 
PARTITION BY toDate(column1) 
ORDER BY (column1, column2, column3)

And when running

alter table table1 modify column column3 LowCardinality(String);

ClickHouse gives

DB::Exception: ALTER of key column column3 must be metadata-only (version 19.6.2.11 (official build))

What does it mean and can it be bypassed?

comp-lowcardinality question

Most helpful comment

@CurtizJ Changing the type to LowCardinality indeed causes column rewrite.
But the primary.idx is not modified by this transformation.

It means that now we can support it.

All 7 comments

column3 is included in primary key. You can modify it only if data is not modified during alter. But changing type to LowCardinality causes data modification and this action is not supported.
As a solution you can create new table with column3 LowCardinality(String) and copy the data to it using the INSERT SELECT query.

Understand, thanks. Maybe the message could be more explicit?

.

@simPod, do you have any further questions?

@blinkov only as a feedback, if you wish to improve the error msg or not. Can be closed.

@CurtizJ Changing the type to LowCardinality indeed causes column rewrite.
But the primary.idx is not modified by this transformation.

It means that now we can support it.

I assign to @alesapin because he has recently done a big rewrite of ALTER mechanics and now this task looks easy to implement.

Was this page helpful?
0 / 5 - 0 ratings