From a77596b36252a41d8026b83265d97513d0002fbb Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Thu, 5 Nov 2020 20:14:18 +0300 Subject: [PATCH] Update complie expressions. --- src/Interpreters/ExpressionJIT.cpp | 51 +++++++++++++++--------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/Interpreters/ExpressionJIT.cpp b/src/Interpreters/ExpressionJIT.cpp index b63e45eaee3..d932e4f2a1f 100644 --- a/src/Interpreters/ExpressionJIT.cpp +++ b/src/Interpreters/ExpressionJIT.cpp @@ -795,7 +795,6 @@ void ActionsDAG::compileFunctions() }; std::unordered_map data; - std::unordered_map constants; for (const auto & node : nodes) data[&node].is_compilable = isCompilableConstant(node) || isCompilableFunction(node); @@ -847,41 +846,43 @@ void ActionsDAG::compileFunctions() cur.num_inlineable_nodes += data[child].num_inlineable_nodes; /// Check if we should inline current node. + bool should_compile = true; /// Inline parents instead of node is possible. if (!cur.used_in_result && cur.all_parents_compilable) - continue; + should_compile = false; /// There is not reason to inline single node. /// The result of compiling function in isolation is pretty much the same as its `execute` method. if (cur.num_inlineable_nodes <= 1) - continue; + should_compile = false;; - /// Compile. - std::vector new_children; - auto dag = getCompilableDAG(frame.node, new_children); - if (dag.size() != cur.num_inlineable_nodes) - throw Exception(ErrorCodes::LOGICAL_ERROR, - "Unexpected number of nodes in compile expression DAG. " - "Expected {}, got {}. Chain: {}", - cur.num_inlineable_nodes, dag.size(), dag.dump()); - - if (auto fn = compile(dag, min_count_to_compile_expression, compilation_cache)) + if (should_compile) { - /// Replace current node to compilable function. + std::vector new_children; + auto dag = getCompilableDAG(frame.node, new_children); + if (dag.size() != cur.num_inlineable_nodes) + throw Exception(ErrorCodes::LOGICAL_ERROR, + "Unexpected number of nodes in compile expression DAG. " + "Expected {}, got {}. Chain: {}", + cur.num_inlineable_nodes, dag.size(), dag.dump()); - ColumnsWithTypeAndName arguments; - arguments.reserve(new_children.size()); - for (const auto * child : new_children) - arguments.emplace_back( - ColumnWithTypeAndName{child->column, child->result_type, child->result_name}); + if (auto fn = compile(dag, min_count_to_compile_expression, compilation_cache)) + { + /// Replace current node to compilable function. - frame.node->type = ActionsDAG::Type::FUNCTION; - frame.node->function_base = fn; - frame.node->function = fn->prepare(arguments); - frame.node->children.swap(new_children); - frame.node->is_function_compiled = true; - frame.node->column = nullptr; /// Just in case. + ColumnsWithTypeAndName arguments; + arguments.reserve(new_children.size()); + for (const auto * child : new_children) + arguments.emplace_back(child->column, child->result_type, child->result_name); + + frame.node->type = ActionsDAG::Type::FUNCTION; + frame.node->function_base = fn; + frame.node->function = fn->prepare(arguments); + frame.node->children.swap(new_children); + frame.node->is_function_compiled = true; + frame.node->column = nullptr; /// Just in case. + } } }