mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
materialize ttl recalculate only (optional)
This commit is contained in:
parent
6f42ec6b9b
commit
bd3d9a4518
@ -429,7 +429,6 @@ class IColumn;
|
|||||||
M(Bool, allow_nondeterministic_mutations, false, "Allow non-deterministic functions in ALTER UPDATE/ALTER DELETE statements", 0) \
|
M(Bool, allow_nondeterministic_mutations, false, "Allow non-deterministic functions in ALTER UPDATE/ALTER DELETE statements", 0) \
|
||||||
M(Seconds, lock_acquire_timeout, DBMS_DEFAULT_LOCK_ACQUIRE_TIMEOUT_SEC, "How long locking request should wait before failing", 0) \
|
M(Seconds, lock_acquire_timeout, DBMS_DEFAULT_LOCK_ACQUIRE_TIMEOUT_SEC, "How long locking request should wait before failing", 0) \
|
||||||
M(Bool, materialize_ttl_after_modify, true, "Apply TTL for old data, after ALTER MODIFY TTL query", 0) \
|
M(Bool, materialize_ttl_after_modify, true, "Apply TTL for old data, after ALTER MODIFY TTL query", 0) \
|
||||||
M(Bool, materialize_ttl_recalculate_only, false, "only recalculate ttl info when MATERIALIZE TTL", 0) \
|
|
||||||
M(String, function_implementation, "", "Choose function implementation for specific target or variant (experimental). If empty enable all of them.", 0) \
|
M(String, function_implementation, "", "Choose function implementation for specific target or variant (experimental). If empty enable all of them.", 0) \
|
||||||
M(Bool, allow_experimental_geo_types, false, "Allow geo data types such as Point, Ring, Polygon, MultiPolygon", 0) \
|
M(Bool, allow_experimental_geo_types, false, "Allow geo data types such as Point, Ring, Polygon, MultiPolygon", 0) \
|
||||||
M(Bool, data_type_default_nullable, false, "Data types without NULL or NOT NULL will make Nullable", 0) \
|
M(Bool, data_type_default_nullable, false, "Data types without NULL or NOT NULL will make Nullable", 0) \
|
||||||
|
@ -303,6 +303,15 @@ static NameSet getKeyColumns(const StoragePtr & storage, const StorageMetadataPt
|
|||||||
return key_columns;
|
return key_columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool materializeTTLRecalculateOnly(const StoragePtr & storage)
|
||||||
|
{
|
||||||
|
auto storage_from_merge_tree_data_part = std::dynamic_pointer_cast<StorageFromMergeTreeDataPart>(storage);
|
||||||
|
if (!storage_from_merge_tree_data_part)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return storage_from_merge_tree_data_part->materializeTTLRecalculateOnly();
|
||||||
|
}
|
||||||
|
|
||||||
static void validateUpdateColumns(
|
static void validateUpdateColumns(
|
||||||
const StoragePtr & storage,
|
const StoragePtr & storage,
|
||||||
const StorageMetadataPtr & metadata_snapshot, const NameSet & updated_columns,
|
const StorageMetadataPtr & metadata_snapshot, const NameSet & updated_columns,
|
||||||
@ -394,7 +403,7 @@ ASTPtr MutationsInterpreter::prepare(bool dry_run)
|
|||||||
NamesAndTypesList all_columns = columns_desc.getAllPhysical();
|
NamesAndTypesList all_columns = columns_desc.getAllPhysical();
|
||||||
|
|
||||||
NameSet updated_columns;
|
NameSet updated_columns;
|
||||||
bool materialize_ttl_recalculate_only = context->getSettingsRef().materialize_ttl_recalculate_only;
|
bool materialize_ttl_recalculate_only = materializeTTLRecalculateOnly(storage);
|
||||||
for (const MutationCommand & command : commands)
|
for (const MutationCommand & command : commands)
|
||||||
{
|
{
|
||||||
if (command.type == MutationCommand::Type::UPDATE
|
if (command.type == MutationCommand::Type::UPDATE
|
||||||
|
@ -117,6 +117,7 @@ struct Settings;
|
|||||||
M(Int64, merge_with_ttl_timeout, 3600 * 4, "Minimal time in seconds, when merge with delete TTL can be repeated.", 0) \
|
M(Int64, merge_with_ttl_timeout, 3600 * 4, "Minimal time in seconds, when merge with delete TTL can be repeated.", 0) \
|
||||||
M(Int64, merge_with_recompression_ttl_timeout, 3600 * 4, "Minimal time in seconds, when merge with recompression TTL can be repeated.", 0) \
|
M(Int64, merge_with_recompression_ttl_timeout, 3600 * 4, "Minimal time in seconds, when merge with recompression TTL can be repeated.", 0) \
|
||||||
M(Bool, ttl_only_drop_parts, false, "Only drop altogether the expired parts and not partially prune them.", 0) \
|
M(Bool, ttl_only_drop_parts, false, "Only drop altogether the expired parts and not partially prune them.", 0) \
|
||||||
|
M(Bool, materialize_ttl_recalculate_only, false, "Only recalculate ttl info when MATERIALIZE TTL", 0) \
|
||||||
M(Bool, write_final_mark, 1, "Write final mark after end of column (0 - disabled, do nothing if index_granularity_bytes=0)", 0) \
|
M(Bool, write_final_mark, 1, "Write final mark after end of column (0 - disabled, do nothing if index_granularity_bytes=0)", 0) \
|
||||||
M(Bool, enable_mixed_granularity_parts, 1, "Enable parts with adaptive and non adaptive granularity", 0) \
|
M(Bool, enable_mixed_granularity_parts, 1, "Enable parts with adaptive and non adaptive granularity", 0) \
|
||||||
M(MaxThreads, max_part_loading_threads, 0, "The number of threads to load data parts at startup.", 0) \
|
M(MaxThreads, max_part_loading_threads, 0, "The number of threads to load data parts at startup.", 0) \
|
||||||
|
@ -72,6 +72,11 @@ public:
|
|||||||
return parts.front()->storage.getPartitionIDFromQuery(ast, context);
|
return parts.front()->storage.getPartitionIDFromQuery(ast, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool materializeTTLRecalculateOnly() const
|
||||||
|
{
|
||||||
|
return parts.front()->storage.getSettings()->materialize_ttl_recalculate_only;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
StorageFromMergeTreeDataPart(const MergeTreeData::DataPartPtr & part_)
|
StorageFromMergeTreeDataPart(const MergeTreeData::DataPartPtr & part_)
|
||||||
: IStorage(getIDFromPart(part_))
|
: IStorage(getIDFromPart(part_))
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
2 b
|
2 b
|
||||||
3 c
|
3 c
|
||||||
4 d
|
4 d
|
||||||
2100-01-01 00:00:00
|
2000-01-01 00:00:00 2100-01-01 00:00:00
|
||||||
1 a
|
1 a
|
||||||
3 c
|
3 c
|
||||||
=============
|
=============
|
||||||
@ -43,7 +43,7 @@
|
|||||||
2 b
|
2 b
|
||||||
3 c
|
3 c
|
||||||
4 d
|
4 d
|
||||||
2100-01-01 00:00:00
|
2000-01-01 00:00:00 2100-01-01 00:00:00
|
||||||
1 a
|
1 a
|
||||||
2 b
|
2 b
|
||||||
4 d
|
4 d
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
set mutations_sync = 2;
|
set mutations_sync = 2;
|
||||||
set materialize_ttl_recalculate_only = true;
|
|
||||||
|
|
||||||
drop table if exists ttl;
|
drop table if exists ttl;
|
||||||
|
|
||||||
create table ttl (d Date, a Int) engine = MergeTree order by a partition by toDayOfMonth(d)
|
create table ttl (d Date, a Int) engine = MergeTree order by a partition by toDayOfMonth(d)
|
||||||
SETTINGS max_number_of_merges_with_ttl_in_pool=0;
|
SETTINGS max_number_of_merges_with_ttl_in_pool=0,materialize_ttl_recalculate_only=true;
|
||||||
|
|
||||||
insert into ttl values (toDateTime('2000-10-10 00:00:00'), 1);
|
insert into ttl values (toDateTime('2000-10-10 00:00:00'), 1);
|
||||||
insert into ttl values (toDateTime('2000-10-10 00:00:00'), 2);
|
insert into ttl values (toDateTime('2000-10-10 00:00:00'), 2);
|
||||||
@ -22,13 +21,13 @@ select '=============';
|
|||||||
drop table if exists ttl;
|
drop table if exists ttl;
|
||||||
|
|
||||||
create table ttl (i Int, s String) engine = MergeTree order by i
|
create table ttl (i Int, s String) engine = MergeTree order by i
|
||||||
SETTINGS max_number_of_merges_with_ttl_in_pool=0;
|
SETTINGS max_number_of_merges_with_ttl_in_pool=0,materialize_ttl_recalculate_only=true;
|
||||||
|
|
||||||
insert into ttl values (1, 'a') (2, 'b') (3, 'c') (4, 'd');
|
insert into ttl values (1, 'a') (2, 'b') (3, 'c') (4, 'd');
|
||||||
|
|
||||||
alter table ttl modify ttl i % 2 = 0 ? today() - 10 : toDate('2100-01-01');
|
alter table ttl modify ttl i % 2 = 0 ? toDate('2000-01-01') : toDate('2100-01-01');
|
||||||
select * from ttl order by i;
|
select * from ttl order by i;
|
||||||
select delete_ttl_info_max from system.parts where table = 'ttl' and active > 0;
|
select delete_ttl_info_min, delete_ttl_info_max from system.parts where table = 'ttl' and active > 0;
|
||||||
optimize table ttl final;
|
optimize table ttl final;
|
||||||
select * from ttl order by i;
|
select * from ttl order by i;
|
||||||
select '=============';
|
select '=============';
|
||||||
@ -43,7 +42,7 @@ select '=============';
|
|||||||
drop table if exists ttl;
|
drop table if exists ttl;
|
||||||
|
|
||||||
create table ttl (i Int, s String) engine = MergeTree order by i
|
create table ttl (i Int, s String) engine = MergeTree order by i
|
||||||
SETTINGS max_number_of_merges_with_ttl_in_pool=0;
|
SETTINGS max_number_of_merges_with_ttl_in_pool=0,materialize_ttl_recalculate_only=true;
|
||||||
|
|
||||||
insert into ttl values (1, 'a') (2, 'b') (3, 'c') (4, 'd');
|
insert into ttl values (1, 'a') (2, 'b') (3, 'c') (4, 'd');
|
||||||
|
|
||||||
@ -62,13 +61,13 @@ select '=============';
|
|||||||
drop table if exists ttl;
|
drop table if exists ttl;
|
||||||
|
|
||||||
create table ttl (d Date, i Int, s String) engine = MergeTree order by i
|
create table ttl (d Date, i Int, s String) engine = MergeTree order by i
|
||||||
SETTINGS max_number_of_merges_with_ttl_in_pool=0;
|
SETTINGS max_number_of_merges_with_ttl_in_pool=0,materialize_ttl_recalculate_only=true;
|
||||||
|
|
||||||
insert into ttl values (toDate('2000-01-02'), 1, 'a') (toDate('2000-01-03'), 2, 'b') (toDate('2080-01-01'), 3, 'c') (toDate('2080-01-03'), 4, 'd');
|
insert into ttl values (toDate('2000-01-02'), 1, 'a') (toDate('2000-01-03'), 2, 'b') (toDate('2080-01-01'), 3, 'c') (toDate('2080-01-03'), 4, 'd');
|
||||||
|
|
||||||
alter table ttl modify ttl i % 3 = 0 ? today() - 10 : toDate('2100-01-01');
|
alter table ttl modify ttl i % 3 = 0 ? toDate('2000-01-01') : toDate('2100-01-01');
|
||||||
select i, s from ttl order by i;
|
select i, s from ttl order by i;
|
||||||
select delete_ttl_info_max from system.parts where table = 'ttl' and active > 0;
|
select delete_ttl_info_min, delete_ttl_info_max from system.parts where table = 'ttl' and active > 0;
|
||||||
optimize table ttl final;
|
optimize table ttl final;
|
||||||
select i, s from ttl order by i;
|
select i, s from ttl order by i;
|
||||||
select '=============';
|
select '=============';
|
||||||
@ -82,7 +81,7 @@ select '=============';
|
|||||||
drop table if exists ttl;
|
drop table if exists ttl;
|
||||||
|
|
||||||
create table ttl (i Int, s String, t String) engine = MergeTree order by i
|
create table ttl (i Int, s String, t String) engine = MergeTree order by i
|
||||||
SETTINGS max_number_of_merges_with_ttl_in_pool=0;
|
SETTINGS max_number_of_merges_with_ttl_in_pool=0,materialize_ttl_recalculate_only=true;
|
||||||
|
|
||||||
insert into ttl values (1, 'a', 'aa') (2, 'b', 'bb') (3, 'c', 'cc') (4, 'd', 'dd');
|
insert into ttl values (1, 'a', 'aa') (2, 'b', 'bb') (3, 'c', 'cc') (4, 'd', 'dd');
|
||||||
|
|
||||||
@ -100,7 +99,7 @@ drop table if exists ttl;
|
|||||||
|
|
||||||
-- Nothing changed, don't run mutation
|
-- Nothing changed, don't run mutation
|
||||||
create table ttl (i Int, s String ttl toDate('2000-01-02')) engine = MergeTree order by i
|
create table ttl (i Int, s String ttl toDate('2000-01-02')) engine = MergeTree order by i
|
||||||
SETTINGS max_number_of_merges_with_ttl_in_pool=0;
|
SETTINGS max_number_of_merges_with_ttl_in_pool=0,materialize_ttl_recalculate_only=true;
|
||||||
|
|
||||||
alter table ttl modify column s String ttl toDate('2000-01-02');
|
alter table ttl modify column s String ttl toDate('2000-01-02');
|
||||||
select count() from system.mutations where table = 'ttl' and is_done;
|
select count() from system.mutations where table = 'ttl' and is_done;
|
||||||
|
Loading…
Reference in New Issue
Block a user