Search code examples
clickhouse

Is the table TTL in clickhouse transactional?


When rows in the table expire according to TTL expiration does Clickhouse remove them immediately and remove all, so you won't see some intermediate states when doing queries? Or If I use group by clause in the TTL expression does it guarantee that aggregation will be applied to all expired records?


Solution

  • It's not atomic (it's atomic on a part level (NOT PARTITION !!!!)).

    TTL expression does NOT guarantee anything. You can see partial result. TTL expression works eventually. Data may be removed sometime in the future OR NEVER.

    About NEVER: There are merge_tree settings

    merge_with_ttl_timeout  │ 14400 
    Minimal time in seconds, when merge with delete TTL can be repeated.
    
    max_replicated_merges_with_ttl_in_queue  │ 1
    How many tasks of merging parts with TTL are allowed simultaneously in ReplicatedMergeTree queue.
    
    max_number_of_merges_with_ttl_in_pool  │ 2 
    When there is more than specified number of merges with TTL entries in pool, do not assign new merge with TTL. This is to leave free threads for regular merges and avoid "Too many parts"
    

    TTL wakes up every 4 hours (merge_with_ttl_timeout) and processes limited number of parts if there are free threads in merge tree pool. If the number of partitions which should be processed by TTL is big or there is no free resources in mergetree pool then TTL will not be able to keep up.