ALTERAR TTL
Você pode alterar o TTL da tabela com uma consulta no seguinte formato:
ALTER TABLE [db.]table_name [ON CLUSTER cluster] MODIFY TTL ttl_expression;REMOVER TTL
A propriedade TTL pode ser removida da tabela com a consulta a seguir:
ALTER TABLE [db.]table_name [ON CLUSTER cluster] REMOVE TTLExemplo
Considere a tabela com TTL de tabela:
CREATE TABLE table_with_ttl
(
event_time DateTime,
UserID UInt64,
Comment String
)
ENGINE MergeTree()
ORDER BY tuple()
TTL event_time + INTERVAL 3 MONTH
SETTINGS min_bytes_for_wide_part = 0;
INSERT INTO table_with_ttl VALUES (now(), 1, 'username1');
INSERT INTO table_with_ttl VALUES (now() - INTERVAL 4 MONTH, 2, 'username2');Execute OPTIMIZE para forçar a limpeza do TTL:
OPTIMIZE TABLE table_with_ttl FINAL;
SELECT * FROM table_with_ttl FORMAT PrettyCompact;A segunda linha foi excluída da tabela.
┌─────────event_time────┬──UserID─┬─────Comment──┐
│ 2020-12-11 12:44:57 │ 1 │ username1 │
└───────────────────────┴─────────┴──────────────┘Agora, remova o TTL da tabela com a seguinte consulta:
ALTER TABLE table_with_ttl REMOVE TTL;Reinsira a linha excluída e force novamente a limpeza do TTL com OPTIMIZE:
INSERT INTO table_with_ttl VALUES (now() - INTERVAL 4 MONTH, 2, 'username2');
OPTIMIZE TABLE table_with_ttl FINAL;
SELECT * FROM table_with_ttl FORMAT PrettyCompact;O TTL não está mais lá, então a segunda linha não é excluída:
┌─────────event_time────┬──UserID─┬─────Comment──┐
│ 2020-12-11 12:44:57 │ 1 │ username1 │
│ 2020-08-11 12:44:57 │ 2 │ username2 │
└───────────────────────┴─────────┴──────────────┘Veja também
- Mais informações sobre a expressão TTL.
- Modifique a coluna com TTL.