From cdf78828da6196dead7baf8269d7d60bad15fb19 Mon Sep 17 00:00:00 2001 From: Nikita Vasilev Date: Fri, 7 May 2021 13:49:05 +0300 Subject: [PATCH] fix --- src/Interpreters/ComparisonGraph.cpp | 2 ++ src/Interpreters/TreeCNFConverter.cpp | 12 +++++++++--- src/Storages/ConstraintsDescription.cpp | 7 +++++++ src/Storages/MergeTree/SubstituteColumnOptimizer.cpp | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Interpreters/ComparisonGraph.cpp b/src/Interpreters/ComparisonGraph.cpp index 4f0f6b919a8..401abf97531 100644 --- a/src/Interpreters/ComparisonGraph.cpp +++ b/src/Interpreters/ComparisonGraph.cpp @@ -36,6 +36,8 @@ ASTPtr ComparisonGraph::normalizeAtom(const ASTPtr & atom) ComparisonGraph::ComparisonGraph(const std::vector & atomic_formulas) { + if (atomic_formulas.empty()) + return; static const std::unordered_map relation_to_enum = { {"equals", Edge::Type::EQUAL}, diff --git a/src/Interpreters/TreeCNFConverter.cpp b/src/Interpreters/TreeCNFConverter.cpp index 8c731cb5a7b..aefedacb741 100644 --- a/src/Interpreters/TreeCNFConverter.cpp +++ b/src/Interpreters/TreeCNFConverter.cpp @@ -8,6 +8,7 @@ namespace DB namespace ErrorCodes { extern const int LOGICAL_ERROR; + extern const int INCORRECT_QUERY; } /// Splits AND(a, b, c) to AND(a, AND(b, c)) for AND/OR @@ -17,6 +18,9 @@ void splitMultiLogic(ASTPtr & node) if (func && (func->name == "and" || func->name == "or")) { + if (func->arguments->children.size() < 2) + throw Exception("Bad logical function", ErrorCodes::INCORRECT_QUERY); + if (func->arguments->children.size() > 2) { ASTPtr res = func->arguments->children.front()->clone(); @@ -58,7 +62,7 @@ void traversePushNot(ASTPtr & node, bool add_negation) else if (func && func->name == "not") { if (func->arguments->children.size() != 1) - throw Exception("Bad NOT function.", ErrorCodes::LOGICAL_ERROR); + throw Exception("Bad NOT function.", ErrorCodes::INCORRECT_QUERY); /// delete NOT node = func->arguments->children[0]->clone(); @@ -98,7 +102,7 @@ void pushOr(ASTPtr & query) auto * or_func = or_node.get()->as(); if (or_func->arguments->children.size() != 2) - throw Exception("Bad OR function.", ErrorCodes::LOGICAL_ERROR); + throw Exception("Bad OR function", ErrorCodes::LOGICAL_ERROR); /// find or upper than and size_t and_node_id = or_func->arguments->children.size(); @@ -117,7 +121,7 @@ void pushOr(ASTPtr & query) const auto * and_func = or_func->arguments->children[and_node_id]->as(); if (and_func->arguments->children.size() != 2) - throw Exception("Bad AND function.", ErrorCodes::LOGICAL_ERROR); + throw Exception("Bad AND function", ErrorCodes::LOGICAL_ERROR); auto a = or_func->arguments->children[other_node_id]; auto b = and_func->arguments->children[0]; @@ -159,6 +163,8 @@ void traverseCNF(const ASTPtr & node, CNFQuery::AndGroup & and_group, CNFQuery:: } else if (func && func->name == "not") { + if (func->arguments->children.size() != 1) + throw Exception("Bad NOT function", ErrorCodes::INCORRECT_QUERY); or_group.insert(CNFQuery::AtomicFormula{true, func->arguments->children.front()}); } else diff --git a/src/Storages/ConstraintsDescription.cpp b/src/Storages/ConstraintsDescription.cpp index 7fc5d8fc1cf..b06896a4ff0 100644 --- a/src/Storages/ConstraintsDescription.cpp +++ b/src/Storages/ConstraintsDescription.cpp @@ -204,6 +204,13 @@ ConstraintsDescription & ConstraintsDescription::operator=(const ConstraintsDesc void ConstraintsDescription::update() { + if (constraints.empty()) + { + cnf_constraints.clear(); + ast_to_atom_ids.clear(); + graph = std::make_unique(std::vector()); + return; + } cnf_constraints = buildConstraintData(); ast_to_atom_ids.clear(); for (size_t i = 0; i < cnf_constraints.size(); ++i) diff --git a/src/Storages/MergeTree/SubstituteColumnOptimizer.cpp b/src/Storages/MergeTree/SubstituteColumnOptimizer.cpp index 83a52daf3e4..5c38b268098 100644 --- a/src/Storages/MergeTree/SubstituteColumnOptimizer.cpp +++ b/src/Storages/MergeTree/SubstituteColumnOptimizer.cpp @@ -244,7 +244,7 @@ void SubstituteColumnOptimizer::perform() return; } - const auto compare_graph = metadata_snapshot->getConstraints().getGraph(); + const auto & compare_graph = metadata_snapshot->getConstraints().getGraph(); // Fill aliases if (select_query->select())