mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-17 20:02:05 +00:00
Fix indices calculation during merge
This commit is contained in:
parent
ce6db6927b
commit
ad6447398f
@ -108,4 +108,15 @@ IndicesDescription IndicesDescription::parse(const String & str, const ColumnsDe
|
||||
return result;
|
||||
}
|
||||
|
||||
ExpressionActionsPtr IndicesDescription::getSingleExpressionForIndices(const ColumnsDescription & columns, const Context & context) const
|
||||
{
|
||||
ASTPtr combined_expr_list = std::make_shared<ASTExpressionList>();
|
||||
for (const auto & index : *this)
|
||||
for (const auto & index_expr : index.expression_list_ast->children)
|
||||
combined_expr_list->children.push_back(index_expr->clone());
|
||||
|
||||
auto syntax_result = SyntaxAnalyzer(context).analyze(combined_expr_list, columns.getAllPhysical());
|
||||
return ExpressionAnalyzer(combined_expr_list, syntax_result, context).getActions(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,6 +59,9 @@ struct IndicesDescription : public std::vector<IndexDescription>
|
||||
String toString() const;
|
||||
/// Parse description from string
|
||||
static IndicesDescription parse(const String & str, const ColumnsDescription & columns, const Context & context);
|
||||
|
||||
/// Return common expression for all stored indices
|
||||
ExpressionActionsPtr getSingleExpressionForIndices(const ColumnsDescription & columns, const Context & context) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -792,13 +792,15 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mergePartsToTempor
|
||||
if (need_remove_expired_values)
|
||||
merged_stream = std::make_shared<TTLBlockInputStream>(merged_stream, data, new_data_part, time_of_merge, force_ttl);
|
||||
|
||||
const auto & index_factory = MergeTreeIndexFactory::instance();
|
||||
|
||||
if (data.hasSecondaryIndices())
|
||||
{
|
||||
merged_stream = std::make_shared<ExpressionBlockInputStream>(merged_stream, data.getPrimaryKeyAndSkipIndicesExpression());
|
||||
const auto & indices = data.getSecondaryIndices();
|
||||
merged_stream = std::make_shared<ExpressionBlockInputStream>(merged_stream, indices.getSingleExpressionForIndices(data.getColumns(), data.global_context));
|
||||
merged_stream = std::make_shared<MaterializingBlockInputStream>(merged_stream);
|
||||
}
|
||||
|
||||
const auto & index_factory = MergeTreeIndexFactory::instance();
|
||||
MergedBlockOutputStream to{
|
||||
new_data_part,
|
||||
merging_columns,
|
||||
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1,14 @@
|
||||
drop table if exists data_01292;
|
||||
|
||||
create table data_01292 (
|
||||
key Int,
|
||||
index key_idx (key) type minmax granularity 1
|
||||
) Engine=MergeTree() ORDER BY (key+0);
|
||||
|
||||
insert into data_01292 values (1);
|
||||
|
||||
optimize table data_01292 final;
|
||||
|
||||
select * from data_01292 where key > 0;
|
||||
|
||||
drop table if exists data_01292;
|
Loading…
Reference in New Issue
Block a user