Merge pull request #9 from nikvas0/nikvas0/fix_duplicate_idx

Nikvas0/fix duplicate idx
This commit is contained in:
Nikita Vasilev 2019-01-17 21:25:24 +03:00 committed by GitHub
commit 9975286a3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 17 deletions

View File

@ -356,36 +356,49 @@ void MergeTreeData::setSkipIndices(const ASTPtr &indices_asts, bool only_check)
if (!only_check)
{
skip_indices_ast = nullptr;
skip_indices_expr = nullptr;
skip_indices.clear();
}
return;
}
MergeTreeIndices new_indexes;
MergeTreeIndices new_indices;
std::set<String> names;
auto index_list = std::dynamic_pointer_cast<ASTExpressionList>(indices_asts);
ASTPtr indices_expr_list = std::make_shared<ASTExpressionList>();
for (const auto &index_ast : index_list->children)
for (const auto & index_ast : index_list->children)
{
new_indexes.push_back(
const auto & index_decl = std::dynamic_pointer_cast<ASTIndexDeclaration>(index_ast);
new_indices.push_back(
std::move(MergeTreeIndexFactory::instance().get(
*this,
std::dynamic_pointer_cast<ASTIndexDeclaration>(index_ast),
std::dynamic_pointer_cast<ASTIndexDeclaration>(index_decl->clone()),
global_context)));
if (names.find(new_indexes.back()->name) != names.end())
{
if (names.find(new_indices.back()->name) != names.end())
throw Exception(
"Index with name `" + new_indexes.back()->name + "` already exsists",
"Index with name `" + new_indices.back()->name + "` already exsists",
ErrorCodes::LOGICAL_ERROR);
ASTPtr expr_list = MergeTreeData::extractKeyExpressionList(index_decl->expr->clone());
for (auto expr : expr_list->children)
indices_expr_list->children.push_back(expr->clone());
names.insert(new_indices.back()->name);
}
names.insert(new_indexes.back()->name);
}
auto syntax = SyntaxAnalyzer(global_context, {}).analyze(
indices_expr_list, getColumns().getAllPhysical());
auto new_skip_indices_expr = ExpressionAnalyzer(indices_expr_list, syntax, global_context)
.getActions(false);
if (!only_check)
{
skip_indices_ast = indices_asts;
skip_indices = std::move(new_indexes);
skip_indices_expr = new_skip_indices_expr;
skip_indices = std::move(new_indices);
}
}

View File

@ -585,6 +585,7 @@ public:
/// Secondary (data skipping) indices for MergeTree
MergeTreeIndices skip_indices;
ASTPtr skip_indices_ast;
ExpressionActionsPtr skip_indices_expr;
/// Names of columns for primary key + secondary sorting columns.
Names sorting_key_columns;

View File

@ -636,9 +636,9 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mergePartsToTempor
merge_entry, sum_input_rows_upper_bound, column_sizes, watch_prev_elapsed, merge_alg));
BlockInputStreamPtr stream = std::move(input);
for (const auto & index : data.skip_indices) {
if (data.skip_indices_expr) {
stream = std::make_shared<MaterializingBlockInputStream>(
std::make_shared<ExpressionBlockInputStream>(stream, index->expr));
std::make_shared<ExpressionBlockInputStream>(stream, data.skip_indices_expr));
}
if (data.hasPrimaryKey()) {
@ -911,9 +911,9 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mutatePartToTempor
{
/// All columns are modified, proceed to write a new part from scratch.
for (const auto & index : data.skip_indices)
if (data.skip_indices_expr)
in = std::make_shared<MaterializingBlockInputStream>(
std::make_shared<ExpressionBlockInputStream>(in, index->expr));
std::make_shared<ExpressionBlockInputStream>(in, data.skip_indices_expr));
if (data.hasPrimaryKey())
in = std::make_shared<MaterializingBlockInputStream>(

View File

@ -214,8 +214,8 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataWriter::writeTempPart(BlockWithPa
NamesAndTypesList columns = data.getColumns().getAllPhysical().filter(block.getNames());
MergedBlockOutputStream out(data, new_data_part->getFullPath(), columns, compression_codec);
for (auto index : data.skip_indices)
index->expr->execute(block);
if (data.skip_indices_expr)
data.skip_indices_expr->execute(block);
out.writePrefix();
out.writeWithPermutation(block, perm_ptr);

View File

@ -11,7 +11,8 @@ CREATE TABLE test.minmax_idx
dt Date
) ENGINE = MergeTree()
ORDER BY u64
INDICES idx_all BY (i32, i32 + f64, d, s, e, dt) TYPE minmax GRANULARITY 2,
INDICES idx_all BY (i32, i32 + f64, d, s, e, dt) TYPE minmax GRANULARITY 4,
idx_all2 BY (i32, i32 + f64, d, s, e, dt) TYPE minmax GRANULARITY 2,
idx_2 BY (u64 + toYear(dt), substring(s, 2, 4)) TYPE minmax GRANULARITY 3
SETTINGS index_granularity = 2;