Clickhouse: TTL doen't work

Created on 11 Nov 2019  Β·  4Comments  Β·  Source: ClickHouse/ClickHouse

Which ClickHouse server version to use
19.11.5.28

Which interface to use, if matters
clickhouse-client

Non-default settings, if any
default settings in place

CREATE TABLE :

CREATE TABLE test_database."test_table" (date Date, timestamp UInt64, String name) ENGINE = ReplicatedMergeTree('xxx', 'xxx') PARTITION BY (toDayOfYear(toDateTime(timestamp)),toHour(toDateTime(timestamp))) ORDER BY (name,timestamp)  TTL date + INTERVAL 10 DAY;

result

select date from "test_table" group by date;

β”Œβ”€β”€β”€β”€β”€β”€β”€date─┐
β”‚ 2019-09-28 β”‚
β”‚ 2019-09-29 β”‚
β”‚ 2019-09-30 β”‚
β”‚ 2019-10-01 β”‚
β”‚ 2019-10-02 β”‚
β”‚ 2019-10-03 β”‚
β”‚ 2019-10-04 β”‚
β”‚ 2019-10-05 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

select count(1) from system.parts where active and database='test_database' and toDate(modification_time)='2019-11-11' limit 10 

β”Œβ”€count(1)─┐
β”‚      317 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

select count(1) from system.parts where active and database='test_database' and toDate(modification_time)='2019-10-10' limit 10 

β”Œβ”€count(1)─┐
β”‚        0 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
bug comp-ttl

Most helpful comment

Confirm it. If partition key is created as toDayOfYear(timestamp), the TTL would be failure. But toYYYYMM(timestamp) will success.

My test code:

CREATE DATABASE IF NOT EXISTS test_database;

CREATE TABLE IF NOT EXISTS test_database.test_table (
    timestamp DateTime,
    test      UInt32)
    ENGINE = MergeTree()
    PARTITION BY toYYYYMM(timestamp)
    ORDER BY (timestamp)
    TTL timestamp + INTERVAL 3 DAY
    SETTINGS storage_policy = 'moving_from_ssd_to_hdd', merge_with_ttl_timeout = 60;

CREATE TABLE IF NOT EXISTS test_database.test_table1 (
    timestamp DateTime,
    test      UInt32)
    ENGINE = MergeTree()
    PARTITION BY toDayOfYear(timestamp)
    ORDER BY (timestamp)
    TTL timestamp + INTERVAL 3 DAY
    SETTINGS storage_policy = 'moving_from_ssd_to_hdd', merge_with_ttl_timeout = 60;

INSERT INTO test_database.test_table
    SELECT
        NOW() - INTERVAL number HOUR,
        rand()
    FROM numbers(1000);

INSERT INTO test_database.test_table1
    SELECT
        NOW() - INTERVAL number HOUR,
        rand()
    FROM numbers(1000);

SELECT * FROM test_database.test_table LIMIT 3;
SELECT * FROM test_database.test_table1 LIMIT 3;

All 4 comments

Confirm it. If partition key is created as toDayOfYear(timestamp), the TTL would be failure. But toYYYYMM(timestamp) will success.

My test code:

CREATE DATABASE IF NOT EXISTS test_database;

CREATE TABLE IF NOT EXISTS test_database.test_table (
    timestamp DateTime,
    test      UInt32)
    ENGINE = MergeTree()
    PARTITION BY toYYYYMM(timestamp)
    ORDER BY (timestamp)
    TTL timestamp + INTERVAL 3 DAY
    SETTINGS storage_policy = 'moving_from_ssd_to_hdd', merge_with_ttl_timeout = 60;

CREATE TABLE IF NOT EXISTS test_database.test_table1 (
    timestamp DateTime,
    test      UInt32)
    ENGINE = MergeTree()
    PARTITION BY toDayOfYear(timestamp)
    ORDER BY (timestamp)
    TTL timestamp + INTERVAL 3 DAY
    SETTINGS storage_policy = 'moving_from_ssd_to_hdd', merge_with_ttl_timeout = 60;

INSERT INTO test_database.test_table
    SELECT
        NOW() - INTERVAL number HOUR,
        rand()
    FROM numbers(1000);

INSERT INTO test_database.test_table1
    SELECT
        NOW() - INTERVAL number HOUR,
        rand()
    FROM numbers(1000);

SELECT * FROM test_database.test_table LIMIT 3;
SELECT * FROM test_database.test_table1 LIMIT 3;

It looks like the bug for me too.
I have few tables with

PARTITION BY toMonday(timestamp)
TTL timestamp + toIntervalDay(90)

And, the old data is not deleted also =(
My version is 19.14.7.15

@vvchistiakov TTLs has been significantly improved since 19.14. Please try with 19.16.16 or 20.1.x release.

Also look at merge tree settings related to TTLs:

select * from system.merge_tree_settings where name like '%ttl%';

@CurtizJ Could you please clarify the status of this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

opavader picture opavader  Β·  3Comments

zhicwu picture zhicwu  Β·  3Comments

jimmykuo picture jimmykuo  Β·  3Comments

igor-sh8 picture igor-sh8  Β·  3Comments

fizerkhan picture fizerkhan  Β·  3Comments