Merge pull request #18980 from ClickHouse/fix-expressions-merge

Fix expressions merge
This commit is contained in:
alesapin 2021-01-13 11:16:01 +03:00 committed by GitHub
commit 07431a6494
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 3 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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_)

View File

@ -0,0 +1 @@
\N \N

View 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)
)