mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 16:50:48 +00:00
Merge pull request #18980 from ClickHouse/fix-expressions-merge
Fix expressions merge
This commit is contained in:
commit
07431a6494
@ -544,6 +544,11 @@ std::string ActionsDAG::dumpDAG() const
|
||||
out << "\n";
|
||||
}
|
||||
|
||||
out << "Index:";
|
||||
for (const auto * node : index)
|
||||
out << ' ' << map[node];
|
||||
out << '\n';
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
@ -692,7 +697,8 @@ ActionsDAGPtr ActionsDAG::merge(ActionsDAG && first, ActionsDAG && second)
|
||||
/// Will store merged result in `first`.
|
||||
|
||||
/// This map contains nodes which should be removed from `first` index, cause they are used as inputs for `second`.
|
||||
std::unordered_set<Node *> removed_first_result;
|
||||
/// The second element is the number of removes (cause one node may be repeated several times in result).
|
||||
std::unordered_map<Node *, size_t> removed_first_result;
|
||||
/// Map inputs of `second` to nodes of `first`.
|
||||
std::unordered_map<Node *, Node *> inputs_map;
|
||||
|
||||
@ -717,7 +723,7 @@ ActionsDAGPtr ActionsDAG::merge(ActionsDAG && first, ActionsDAG && second)
|
||||
else
|
||||
{
|
||||
inputs_map[node] = it->second.front();
|
||||
removed_first_result.emplace(it->second.front());
|
||||
removed_first_result[it->second.front()] += 1;
|
||||
it->second.pop_front();
|
||||
}
|
||||
}
|
||||
@ -761,8 +767,12 @@ ActionsDAGPtr ActionsDAG::merge(ActionsDAG && first, ActionsDAG && second)
|
||||
auto cur = it;
|
||||
++it;
|
||||
|
||||
if (removed_first_result.count(*cur))
|
||||
auto jt = removed_first_result.find(*cur);
|
||||
if (jt != removed_first_result.end() && jt->second > 0)
|
||||
{
|
||||
first.index.remove(cur);
|
||||
--jt->second;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto * node : second.index)
|
||||
|
@ -87,6 +87,7 @@ public:
|
||||
const Actions & getActions() const { return actions; }
|
||||
const std::list<Node> & getNodes() const { return actions_dag->getNodes(); }
|
||||
const ActionsDAG & getActionsDAG() const { return *actions_dag; }
|
||||
const ColumnNumbers & getResultPositions() const { return result_positions; }
|
||||
|
||||
/// Get a list of input columns.
|
||||
Names getRequiredColumns() const;
|
||||
|
@ -100,6 +100,11 @@ void ExpressionStep::describeActions(FormatSettings & settings) const
|
||||
first = false;
|
||||
settings.out << action.toString() << '\n';
|
||||
}
|
||||
|
||||
settings.out << prefix << "Positions:";
|
||||
for (const auto & pos : expression->getResultPositions())
|
||||
settings.out << ' ' << pos;
|
||||
settings.out << '\n';
|
||||
}
|
||||
|
||||
JoinStep::JoinStep(const DataStream & input_stream_, JoinPtr join_)
|
||||
|
@ -0,0 +1 @@
|
||||
\N \N
|
21
tests/queries/0_stateless/01650_expressions_merge_bug.sql
Normal file
21
tests/queries/0_stateless/01650_expressions_merge_bug.sql
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
SELECT
|
||||
NULL IN
|
||||
(
|
||||
SELECT
|
||||
9223372036854775807,
|
||||
9223372036854775807
|
||||
),
|
||||
NULL
|
||||
FROM
|
||||
(
|
||||
SELECT DISTINCT
|
||||
NULL,
|
||||
NULL,
|
||||
NULL IN
|
||||
(
|
||||
SELECT (NULL, '-1')
|
||||
),
|
||||
NULL
|
||||
FROM numbers(1024)
|
||||
)
|
Loading…
Reference in New Issue
Block a user