物化列上的 ClickHouse TTL
ClickHouse TTL on materialized column
我正在尝试将 clickhouse 集群从版本 18.8 升级到 19.9.2。以前,我有一个从数据库中删除旧数据的 cronjob。我想开始使用 TTL 功能。
简化的table定义:
CREATE TABLE myTimeseries(
timestamp_ns Int64,
source_id String,
data String,
date Date MATERIALIZED toDate(timestamp_ns/1e9),
time DateTime MATERIALIZED toDateTime(timestamp_ns/1e9))
ENGINE = MergeTree()
PARTITION BY (source_id, toStartOfHour(time))
TTL date + toInterValDay(7)
SETTINGS index_granularity=8192, merge_with_ttl_timeout=43200
问题是,它不会删除旧数据。我在文档中找不到任何有助于调试此问题的内容。
问题:
如何调试这个问题? (有没有办法看看以后什么时候清空数据)?
这可能是因为日期字段被具体化了吗?我有另一个 table,其中日期不是具体化的字段,一切正常。
是的,您可以使用具有 TTL 功能的具体化字段。
我附上了创建 table 的简单查询,每隔 5 分钟删除一次。
它适用于 clickhouse 服务器版本 20.4.5
CREATE TABLE IF NOT EXISTS test.profiling
(
headtime UInt64,
date DateTime MATERIALIZED toDateTime(headtime),
id Int64,
operation_name String,
duration Int64
)
ENGINE MergeTree()
PARTITION BY toYYYYMM(date)
ORDER BY (date, id)
TTL date + INTERVAL 5 MINUTE
来自 clickhouse 的重要提示 documentation:
Data with an expired TTL is removed when ClickHouse merges data parts.
When ClickHouse see that data is expired, it performs an off-schedule
merge. To control the frequency of such merges, you can set
merge_with_ttl_timeout. If the value is too low, it will perform many
off-schedule merges that may consume a lot of resources.
If you perform the SELECT query between merges, you may get expired
data. To avoid it, use the OPTIMIZE query before SELECT.
我正在尝试将 clickhouse 集群从版本 18.8 升级到 19.9.2。以前,我有一个从数据库中删除旧数据的 cronjob。我想开始使用 TTL 功能。
简化的table定义:
CREATE TABLE myTimeseries(
timestamp_ns Int64,
source_id String,
data String,
date Date MATERIALIZED toDate(timestamp_ns/1e9),
time DateTime MATERIALIZED toDateTime(timestamp_ns/1e9))
ENGINE = MergeTree()
PARTITION BY (source_id, toStartOfHour(time))
TTL date + toInterValDay(7)
SETTINGS index_granularity=8192, merge_with_ttl_timeout=43200
问题是,它不会删除旧数据。我在文档中找不到任何有助于调试此问题的内容。
问题:
如何调试这个问题? (有没有办法看看以后什么时候清空数据)?
这可能是因为日期字段被具体化了吗?我有另一个 table,其中日期不是具体化的字段,一切正常。
是的,您可以使用具有 TTL 功能的具体化字段。 我附上了创建 table 的简单查询,每隔 5 分钟删除一次。 它适用于 clickhouse 服务器版本 20.4.5
CREATE TABLE IF NOT EXISTS test.profiling
(
headtime UInt64,
date DateTime MATERIALIZED toDateTime(headtime),
id Int64,
operation_name String,
duration Int64
)
ENGINE MergeTree()
PARTITION BY toYYYYMM(date)
ORDER BY (date, id)
TTL date + INTERVAL 5 MINUTE
来自 clickhouse 的重要提示 documentation:
Data with an expired TTL is removed when ClickHouse merges data parts.
When ClickHouse see that data is expired, it performs an off-schedule merge. To control the frequency of such merges, you can set merge_with_ttl_timeout. If the value is too low, it will perform many off-schedule merges that may consume a lot of resources.
If you perform the SELECT query between merges, you may get expired data. To avoid it, use the OPTIMIZE query before SELECT.