mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Merge pull request #32695 from CurtizJ/fix-add-ttl
Fix `MATERIALIZE TTL` with `TTL WHERE` and `TTL GROUP BY`
This commit is contained in:
commit
bbb981655d
@ -421,6 +421,7 @@ ASTPtr MutationsInterpreter::prepare(bool dry_run)
|
||||
|
||||
NameSet updated_columns;
|
||||
bool materialize_ttl_recalculate_only = materializeTTLRecalculateOnly(storage);
|
||||
|
||||
for (const MutationCommand & command : commands)
|
||||
{
|
||||
if (command.type == MutationCommand::Type::UPDATE
|
||||
@ -631,7 +632,9 @@ ASTPtr MutationsInterpreter::prepare(bool dry_run)
|
||||
dependencies.insert(dependency);
|
||||
}
|
||||
}
|
||||
else if (metadata_snapshot->hasRowsTTL())
|
||||
else if (metadata_snapshot->hasRowsTTL()
|
||||
|| metadata_snapshot->hasAnyRowsWhereTTL()
|
||||
|| metadata_snapshot->hasAnyGroupByTTL())
|
||||
{
|
||||
for (const auto & column : all_columns)
|
||||
dependencies.emplace(column.name, ColumnDependency::TTL_TARGET);
|
||||
|
@ -254,16 +254,24 @@ ColumnDependencies StorageInMemoryMetadata::getColumnDependencies(const NameSet
|
||||
for (const auto & projection : getProjections())
|
||||
add_dependent_columns(&projection, projections_columns);
|
||||
|
||||
if (hasRowsTTL())
|
||||
auto add_for_rows_ttl = [&](const auto & expression, auto & to_set)
|
||||
{
|
||||
auto rows_expression = getRowsTTL().expression;
|
||||
if (add_dependent_columns(rows_expression, required_ttl_columns) && include_ttl_target)
|
||||
if (add_dependent_columns(expression, to_set) && include_ttl_target)
|
||||
{
|
||||
/// Filter all columns, if rows TTL expression have to be recalculated.
|
||||
for (const auto & column : getColumns().getAllPhysical())
|
||||
updated_ttl_columns.insert(column.name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (hasRowsTTL())
|
||||
add_for_rows_ttl(getRowsTTL().expression, required_ttl_columns);
|
||||
|
||||
for (const auto & entry : getRowsWhereTTLs())
|
||||
add_for_rows_ttl(entry.expression, required_ttl_columns);
|
||||
|
||||
for (const auto & entry : getGroupByTTLs())
|
||||
add_for_rows_ttl(entry.expression, required_ttl_columns);
|
||||
|
||||
for (const auto & entry : getRecompressionTTLs())
|
||||
add_dependent_columns(entry.expression, required_ttl_columns);
|
||||
|
41
tests/queries/0_stateless/02129_add_column_add_ttl.reference
Normal file
41
tests/queries/0_stateless/02129_add_column_add_ttl.reference
Normal file
@ -0,0 +1,41 @@
|
||||
0 2021-01-01 0
|
||||
0 2021-01-01 0
|
||||
1 2021-01-01 0
|
||||
1 2021-01-01 0
|
||||
2 2021-01-01 0
|
||||
2 2021-01-01 0
|
||||
3 2021-01-01 0
|
||||
3 2021-01-01 0
|
||||
4 2021-01-01 0
|
||||
4 2021-01-01 0
|
||||
5 2021-01-01 0
|
||||
5 2021-01-01 0
|
||||
6 2021-01-01 0
|
||||
6 2021-01-01 0
|
||||
7 2021-01-01 0
|
||||
7 2021-01-01 0
|
||||
8 2021-01-01 0
|
||||
8 2021-01-01 0
|
||||
9 2021-01-01 0
|
||||
9 2021-01-01 0
|
||||
==========
|
||||
0 2021-01-01 0
|
||||
0 2021-01-01 0
|
||||
1 2021-01-01 0
|
||||
1 2021-01-01 0
|
||||
2 2021-01-01 0
|
||||
2 2021-01-01 0
|
||||
3 2021-01-01 0
|
||||
3 2021-01-01 0
|
||||
4 2021-01-01 0
|
||||
4 2021-01-01 0
|
||||
5 2021-01-01 0
|
||||
5 2021-01-01 0
|
||||
6 2021-01-01 0
|
||||
6 2021-01-01 0
|
||||
7 2021-01-01 0
|
||||
7 2021-01-01 0
|
||||
8 2021-01-01 0
|
||||
8 2021-01-01 0
|
||||
9 2021-01-01 0
|
||||
9 2021-01-01 0
|
31
tests/queries/0_stateless/02129_add_column_add_ttl.sql
Normal file
31
tests/queries/0_stateless/02129_add_column_add_ttl.sql
Normal file
@ -0,0 +1,31 @@
|
||||
drop table if exists ttl_test_02129;
|
||||
|
||||
create table ttl_test_02129(a Int64, b String, d Date)
|
||||
Engine=MergeTree partition by d order by a
|
||||
settings min_bytes_for_wide_part = 0, min_rows_for_wide_part = 0, materialize_ttl_recalculate_only = 0;
|
||||
|
||||
insert into ttl_test_02129 select number, '', '2021-01-01' from numbers(10);
|
||||
alter table ttl_test_02129 add column c Int64 settings mutations_sync=2;
|
||||
|
||||
insert into ttl_test_02129 select number, '', '2021-01-01', 0 from numbers(10);
|
||||
alter table ttl_test_02129 modify TTL (d + INTERVAL 1 MONTH) DELETE WHERE c=1 settings mutations_sync=2;
|
||||
|
||||
select * from ttl_test_02129 order by a, b, d, c;
|
||||
drop table ttl_test_02129;
|
||||
|
||||
drop table if exists ttl_test_02129;
|
||||
|
||||
select '==========';
|
||||
|
||||
create table ttl_test_02129(a Int64, b String, d Date)
|
||||
Engine=MergeTree partition by d order by a
|
||||
settings min_bytes_for_wide_part = 0, min_rows_for_wide_part = 0, materialize_ttl_recalculate_only = 1;
|
||||
|
||||
insert into ttl_test_02129 select number, '', '2021-01-01' from numbers(10);
|
||||
alter table ttl_test_02129 add column c Int64 settings mutations_sync=2;
|
||||
|
||||
insert into ttl_test_02129 select number, '', '2021-01-01', 0 from numbers(10);
|
||||
alter table ttl_test_02129 modify TTL (d + INTERVAL 1 MONTH) DELETE WHERE c=1 settings mutations_sync=2;
|
||||
|
||||
select * from ttl_test_02129 order by a, b, d, c;
|
||||
drop table ttl_test_02129;
|
Loading…
Reference in New Issue
Block a user