Merge pull request #35953 from azat/ttl-mutations

Require mutations for per-table TTL only when it had been changed
This commit is contained in:
Alexander Gololobov 2022-04-13 17:14:04 +02:00 committed by GitHub
commit fcb83a12ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 4 deletions

View File

@ -818,22 +818,27 @@ bool AlterCommand::isCommentAlter() const
bool AlterCommand::isTTLAlter(const StorageInMemoryMetadata & metadata) const bool AlterCommand::isTTLAlter(const StorageInMemoryMetadata & metadata) const
{ {
if (type == MODIFY_TTL) if (type == MODIFY_TTL)
{
if (!metadata.table_ttl.definition_ast)
return true; return true;
/// If TTL had not been changed, do not require mutations
return queryToString(metadata.table_ttl.definition_ast) != queryToString(ttl);
}
if (!ttl || type != MODIFY_COLUMN) if (!ttl || type != MODIFY_COLUMN)
return false; return false;
bool ttl_changed = true; bool column_ttl_changed = true;
for (const auto & [name, ttl_ast] : metadata.columns.getColumnTTLs()) for (const auto & [name, ttl_ast] : metadata.columns.getColumnTTLs())
{ {
if (name == column_name && queryToString(*ttl) == queryToString(*ttl_ast)) if (name == column_name && queryToString(*ttl) == queryToString(*ttl_ast))
{ {
ttl_changed = false; column_ttl_changed = false;
break; break;
} }
} }
return ttl_changed; return column_ttl_changed;
} }
bool AlterCommand::isRemovingProperty() const bool AlterCommand::isRemovingProperty() const

View File

@ -0,0 +1,22 @@
-- { echoOn }
alter table per_table_ttl_02265 modify TTL date + interval 1 month;
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
1
alter table per_table_ttl_02265 modify TTL date + interval 1 month;
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
1
alter table per_table_ttl_02265 modify TTL date + interval 2 month;
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
2
alter table per_table_ttl_02265 modify TTL date + interval 2 month group by key set value = argMax(value, date);
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
3
alter table per_table_ttl_02265 modify TTL date + interval 2 month group by key set value = argMax(value, date);
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
3
alter table per_table_ttl_02265 modify TTL date + interval 2 month recompress codec(ZSTD(17));
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
4
alter table per_table_ttl_02265 modify TTL date + interval 2 month recompress codec(ZSTD(17));
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
4

View File

@ -0,0 +1,22 @@
drop table if exists per_table_ttl_02265;
create table per_table_ttl_02265 (key Int, date Date, value String) engine=MergeTree() order by key;
insert into per_table_ttl_02265 values (1, today(), '1');
-- { echoOn }
alter table per_table_ttl_02265 modify TTL date + interval 1 month;
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
alter table per_table_ttl_02265 modify TTL date + interval 1 month;
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
alter table per_table_ttl_02265 modify TTL date + interval 2 month;
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
alter table per_table_ttl_02265 modify TTL date + interval 2 month group by key set value = argMax(value, date);
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
alter table per_table_ttl_02265 modify TTL date + interval 2 month group by key set value = argMax(value, date);
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
alter table per_table_ttl_02265 modify TTL date + interval 2 month recompress codec(ZSTD(17));
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
alter table per_table_ttl_02265 modify TTL date + interval 2 month recompress codec(ZSTD(17));
select count() from system.mutations where database = currentDatabase() and table = 'per_table_ttl_02265';
-- { echoOff }
drop table per_table_ttl_02265;