diff --git a/src/Interpreters/ActionsDAG.cpp b/src/Interpreters/ActionsDAG.cpp index 4c3a4cbe0fa..e71c60bb540 100644 --- a/src/Interpreters/ActionsDAG.cpp +++ b/src/Interpreters/ActionsDAG.cpp @@ -821,6 +821,13 @@ ActionsDAGPtr ActionsDAG::merge(ActionsDAG && first, ActionsDAG && second) first.nodes.splice(first.nodes.end(), std::move(second.nodes)); + /// Here we rebuild index because some string_view from the first map now may point to string from second. + ActionsDAG::Index first_index; + for (auto * node : first.index) + first_index.insert(node); + + first.index.swap(first_index); + #if USE_EMBEDDED_COMPILER if (first.compilation_cache == nullptr) first.compilation_cache = second.compilation_cache; diff --git a/tests/queries/0_stateless/01672_actions_dag_merge_crash.reference b/tests/queries/0_stateless/01672_actions_dag_merge_crash.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01672_actions_dag_merge_crash.sql b/tests/queries/0_stateless/01672_actions_dag_merge_crash.sql new file mode 100644 index 00000000000..b3b5b3bcd91 --- /dev/null +++ b/tests/queries/0_stateless/01672_actions_dag_merge_crash.sql @@ -0,0 +1 @@ +SELECT [NULL, '25.6', '-0.02', NULL], [NULL], 1024, [NULL, '10485.76', NULL, NULL], [NULL, '-922337203.6854775808', toNullable(NULL)], [NULL] FROM (SELECT [multiIf((number % 1023) = -inf, toString(number), NULL)], NULL, '-1', multiIf((number % NULL) = NULL, toString(number), ''), [NULL, NULL], multiIf((number % NULL) = 65536, toString(number), '') AS s FROM system.numbers) LIMIT 1024 format Null