From 6ed4916d5db5b7823cf11d01c64babf6409565da Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Thu, 26 Nov 2020 22:48:21 +0300 Subject: [PATCH] Fix ActionsDAG::merge --- src/Interpreters/ActionsDAG.cpp | 37 +++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Interpreters/ActionsDAG.cpp b/src/Interpreters/ActionsDAG.cpp index 00ba4d6d21c..874a06c7ef5 100644 --- a/src/Interpreters/ActionsDAG.cpp +++ b/src/Interpreters/ActionsDAG.cpp @@ -707,6 +707,30 @@ ActionsDAGPtr ActionsDAG::merge(ActionsDAG && lhs, ActionsDAG && rhs) } } + /// Replace inputs from rhs to nodes from lhs result. + for (auto & node : rhs.nodes) + { + for (auto & child : node.children) + { + if (child->type == ActionType::INPUT) + { + auto it = inputs_map.find(child); + if (it != inputs_map.end()) + child = it->second; + } + } + } + + for (auto & node : rhs.index) + { + if (node->type == ActionType::INPUT) + { + auto it = inputs_map.find(node); + if (it != inputs_map.end()) + node = it->second; + } + } + /// Update index. if (rhs.settings.project_input) { @@ -729,19 +753,6 @@ ActionsDAGPtr ActionsDAG::merge(ActionsDAG && lhs, ActionsDAG && rhs) lhs.index.insert(node); } - /// Replace inputs from rhs to nodes from lhs result. - for (auto & node : rhs.nodes) - { - for (auto & child : node.children) - { - if (child->type == ActionType::INPUT) - { - auto it = inputs_map.find(child); - if (it != inputs_map.end()) - child = it->second; - } - } - } lhs.nodes.splice(lhs.nodes.end(), std::move(rhs.nodes));