Fix projection materialization with missing columns

This commit is contained in:
Amos Bird 2021-08-10 21:47:27 +08:00
parent 9cbc4b4f7f
commit e63c26edb7
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
6 changed files with 20 additions and 13 deletions

View File

@ -920,9 +920,10 @@ BlockInputStreamPtr MutationsInterpreter::execute()
return result_stream;
}
const Block & MutationsInterpreter::getUpdatedHeader() const
Block MutationsInterpreter::getUpdatedHeader() const
{
return *updated_header;
// If it's an index/projection materialization, we don't write any data columns, thus empty header is used
return mutation_kind.mutation_kind == MutationKind::MUTATE_INDEX_PROJECTION ? Block{} : *updated_header;
}
const ColumnDependencies & MutationsInterpreter::getColumnDependencies() const

View File

@ -53,7 +53,7 @@ public:
BlockInputStreamPtr execute();
/// Only changed columns.
const Block & getUpdatedHeader() const;
Block getUpdatedHeader() const;
const ColumnDependencies & getColumnDependencies() const;

View File

@ -1332,11 +1332,8 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mutatePartToTempor
{
/// We will modify only some of the columns. Other columns and key values can be copied as-is.
NameSet updated_columns;
if (mutation_kind != MutationsInterpreter::MutationKind::MUTATE_INDEX_PROJECTION)
{
for (const auto & name_type : updated_header.getNamesAndTypesList())
updated_columns.emplace(name_type.name);
}
for (const auto & name_type : updated_header.getNamesAndTypesList())
updated_columns.emplace(name_type.name);
auto indices_to_recalc = getIndicesToRecalculate(
in, updated_columns, metadata_snapshot, context, materialized_indices, source_part);
@ -1345,7 +1342,7 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mutatePartToTempor
NameSet files_to_skip = collectFilesToSkip(
source_part,
mutation_kind == MutationsInterpreter::MutationKind::MUTATE_INDEX_PROJECTION ? Block{} : updated_header,
updated_header,
indices_to_recalc,
mrk_extension,
projections_to_recalc);
@ -1413,8 +1410,7 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mutatePartToTempor
metadata_snapshot,
indices_to_recalc,
projections_to_recalc,
// If it's an index/projection materialization, we don't write any data columns, thus empty header is used
mutation_kind == MutationsInterpreter::MutationKind::MUTATE_INDEX_PROJECTION ? Block{} : updated_header,
updated_header,
new_data_part,
in,
time_of_mutation,

View File

@ -361,10 +361,11 @@ QueryPlanPtr MergeTreeDataSelectExecutor::read(
pipes.emplace_back(std::move(projection_pipe));
pipes.emplace_back(std::move(ordinary_pipe));
auto pipe = Pipe::unitePipes(std::move(pipes));
// TODO what if pipe is empty?
pipe.resize(1);
auto step = std::make_unique<ReadFromStorageStep>(std::move(pipe), "MergeTree(with projection)");
auto step = std::make_unique<ReadFromStorageStep>(
std::move(pipe),
fmt::format("MergeTree(with {} projection {})", query_info.projection->desc->type, query_info.projection->desc->name));
auto plan = std::make_unique<QueryPlan>();
plan->addStep(std::move(step));
return plan;

View File

@ -0,0 +1,9 @@
drop table if exists x;
create table x (i int) engine MergeTree order by tuple();
insert into x values (1);
alter table x add column j int;
alter table x add projection p_agg (select sum(j));
alter table x materialize projection p_agg settings mutations_sync = 1;
drop table x;