Merge pull request #69736 from evillique/fix-ttl

Fix METADATA_MISMATCH due to TTL with WHERE
This commit is contained in:
Nikolay Degterinsky 2024-09-19 08:38:55 +00:00 committed by GitHub
commit 3efe136635
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 1 deletions

View File

@ -248,7 +248,9 @@ TTLDescription TTLDescription::getTTLFromAST(
if (ASTPtr where_expr_ast = ttl_element->where())
{
result.where_expression_ast = where_expr_ast->clone();
where_expression = buildExpressionAndSets(where_expr_ast, columns.getAllPhysical(), context).expression;
ASTPtr ast = where_expr_ast->clone();
where_expression = buildExpressionAndSets(ast, columns.getAllPhysical(), context).expression;
result.where_expression_columns = where_expression->getRequiredColumnsWithTypes();
result.where_result_column = where_expression->getSampleBlock().safeGetByPosition(0).name;
}

View File

@ -0,0 +1 @@
CREATE TABLE default.ttl\n(\n `a` UInt32,\n `timestamp` DateTime\n)\nENGINE = MergeTree\nORDER BY a\nTTL timestamp + toIntervalSecond(2) WHERE a IN (\n SELECT number\n FROM system.numbers\n LIMIT 100000\n)\nSETTINGS index_granularity = 8192

View File

@ -0,0 +1,17 @@
DROP TABLE IF EXISTS ttl;
CREATE TABLE ttl
(
`a` UInt32,
`timestamp` DateTime
)
ENGINE = MergeTree
ORDER BY a
TTL timestamp + toIntervalSecond(2) WHERE a IN (
SELECT number
FROM system.numbers
LIMIT 100000
);
SHOW CREATE ttl;
DROP TABLE ttl;