clickhouse 主键字段类型修改
场景:我想把user_id字段类型进行32和64之间的转换,包括有副本的情况(zookeeper)1.UInt64->UInt321.1 建表create table demo(when DateTime,user_id UInt64,bytes UInt64 )engine = MergeTree()ORDER BY user_idSETTINGS index_granularity =
场景:我想把user_id字段类型进行32和64之间的转换,包括有副本的情况(zookeeper)
在修改字段的时候ck会禁用修改,官方推荐的方法是重导数据?重导数据需要很长的时间,非必要不考虑,所以尝试了下如下的方式
1.UInt64->UInt32
1.1 建表
create table demo(
when DateTime,
user_id UInt64,
bytes UInt64 )
engine = MergeTree()
ORDER BY user_id
SETTINGS index_granularity = 8192;
1.2 执行Alter语句报错
ALTER TABLE download modify column user_id UInt32;
Code: 524, e.displayText() = DB::Exception: ALTER of key column user_id from type UInt64 to type UInt32 must be metadata-only (version 20.8.17.25 (official build))
1.3 修改元数据
detach tableName
/var/lib/clickhouse/metadata/找到对应的表修改
attach tableName
2.UInt32->UInt64
注意:UInt32->UInt64如果 PARTITION BY user_id 上,修改类型会导致数据丢失
reate table test02
( when DateTime, user_id UInt64, bytes UInt64 )
engine = MergeTree() PARTITION BY user_id
ORDER BY intHash64(user_id)
SAMPLE BY intHash64(user_id) SETTINGS
index_granularity = 8192, enable_mixed_granularity_parts = 1;
ALTER TABLE test01 modify column user_id UInt64 DB::Exception: ALTER of key column user_id is forbidden (version 20.8.17.25 (official build))
detach tableName
/var/lib/clickhouse/metadata/找到对应的表修改
attach tableName
3.有副本表
需要同时修改zk上的元数据
当修改了元数据,zk没修改的时候 attach会报错
所以要去修改zk上的数据,用prettyzoo, 然后再attach
更多推荐
所有评论(0)