Fix test.

This commit is contained in:
Nikolai Kochetov 2021-02-20 20:42:06 +03:00
parent 2ae0b47edb
commit 00e0dbc3e5
5 changed files with 23 additions and 40 deletions

View File

@ -1217,8 +1217,8 @@ namespace
struct ConjinctionNodes
{
std::unordered_set<ActionsDAG::Node *> allowed;
std::unordered_set<ActionsDAG::Node *> rejected;
std::vector<ActionsDAG::Node *> allowed;
std::vector<ActionsDAG::Node *> rejected;
};
/// Take a node which result is predicate.
@ -1228,6 +1228,8 @@ struct ConjinctionNodes
ConjinctionNodes getConjinctionNodes(ActionsDAG::Node * predicate, std::unordered_set<const ActionsDAG::Node *> allowed_nodes)
{
ConjinctionNodes conjunction;
std::unordered_set<ActionsDAG::Node *> allowed;
std::unordered_set<ActionsDAG::Node *> rejected;
struct Frame
{
@ -1276,12 +1278,19 @@ ConjinctionNodes getConjinctionNodes(ActionsDAG::Node * predicate, std::unordere
else if (is_conjunction)
{
for (auto * child : cur.node->children)
{
if (allowed_nodes.count(child))
conjunction.allowed.insert(child);
{
if (allowed.insert(child).second)
conjunction.allowed.push_back(child);
}
}
}
else if (cur.is_predicate)
{
conjunction.rejected.insert(cur.node);
if (rejected.insert(cur.node).second)
conjunction.rejected.push_back(cur.node);
}
stack.pop();
@ -1291,7 +1300,7 @@ ConjinctionNodes getConjinctionNodes(ActionsDAG::Node * predicate, std::unordere
if (conjunction.allowed.empty())
{
if (allowed_nodes.count(predicate))
conjunction.allowed.insert(predicate);
conjunction.allowed.push_back(predicate);
}
return conjunction;
@ -1322,7 +1331,7 @@ ColumnsWithTypeAndName prepareFunctionArguments(const std::vector<ActionsDAG::No
///
/// Result actions add single column with conjunction result (it is always last in index).
/// No other columns are added or removed.
ActionsDAGPtr ActionsDAG::cloneActionsForConjunction(std::unordered_set<Node *> conjunction)
ActionsDAGPtr ActionsDAG::cloneActionsForConjunction(std::vector<Node *> conjunction)
{
if (conjunction.empty())
return nullptr;
@ -1448,7 +1457,7 @@ ActionsDAGPtr ActionsDAG::splitActionsForFilter(const std::string & filter_name,
/// Now, when actions are created, update current DAG.
if (conjunction.allowed.count(predicate))
if (conjunction.rejected.empty())
{
/// The whole predicate was split.
if (can_remove_filter)

View File

@ -314,7 +314,7 @@ private:
void compileFunctions();
ActionsDAGPtr cloneActionsForConjunction(std::unordered_set<Node *> conjunction);
ActionsDAGPtr cloneActionsForConjunction(std::vector<Node *> conjunction);
};

View File

@ -58,11 +58,12 @@ static size_t tryAddNewFilterStep(
const bool found_filter_column = it != expression->getIndex().end();
if (!found_filter_column && removes_filter)
if (!found_filter_column && !removes_filter)
throw Exception(ErrorCodes::LOGICAL_ERROR,
"Filter column {} was removed from ActionsDAG but it is needed in result. DAG:\n{}",
filter_column_name, expression->dumpDAG());
/// Filter column was replaced to constant.
const bool filter_is_constant = found_filter_column && (*it)->column && isColumnConst(*(*it)->column);
if (!found_filter_column || filter_is_constant)
@ -70,19 +71,6 @@ static size_t tryAddNewFilterStep(
/// Replace current actions to expression, as we don't need to filter anything.
parent = std::make_unique<ExpressionStep>(child->getOutputStream(), expression);
if (it == expression->getIndex().end())
{
/// Filter was removed after split.
}
else if ((*it)->column && isColumnConst(*(*it)->column))
{
/// Filter column was replaced to constant.
parent = std::make_unique<ExpressionStep>(child->getOutputStream(), expression);
}
/// Add new Filter step before Aggregating.
/// Expression/Filter -> Aggregating -> Something
auto & node = nodes.emplace_back();
@ -109,20 +97,6 @@ static Names getAggregatinKeys(const Aggregator::Params & params)
return keys;
}
// static NameSet getColumnNamesFromSortDescription(const SortDescription & sort_desc, const Block & header)
// {
// NameSet names;
// for (const auto & column : sort_desc)
// {
// if (!column.column_name.empty())
// names.insert(column.column_name);
// else
// names.insert(header.safeGetByPosition(column.column_number).name);
// }
// return names;
// }
size_t tryPushDownFilter(QueryPlan::Node * parent_node, QueryPlan::Nodes & nodes)
{
if (parent_node->children.size() != 1)

View File

@ -68,7 +68,7 @@ Filter column: notEquals(y, 0)
9 10
> one condition of filter should be pushed down after aggregating, other two conditions are ANDed
Filter column
FUNCTION and(minus(s, 4) :: 2, minus(s, 8) :: 1) -> and(notEquals(y, 0), minus(s, 8), minus(s, 4))
FUNCTION and(minus(s, 8) :: 1, minus(s, 4) :: 2) -> and(notEquals(y, 0), minus(s, 8), minus(s, 4))
Aggregating
Filter column: notEquals(y, 0)
0 1
@ -83,7 +83,7 @@ Filter column: notEquals(y, 0)
Filter column
ALIAS notEquals(s, 8) :: 1 -> and(notEquals(y, 0), notEquals(s, 8), minus(y, 4))
Aggregating
Filter column: and(minus(y, 4), notEquals(y, 0))
Filter column: and(notEquals(y, 0), minus(y, 4))
0 1
1 2
2 3

View File

@ -66,7 +66,7 @@ $CLICKHOUSE_CLIENT -q "
select sum(x) as s, y from (select number as x, number + 1 as y from numbers(10)) group by y
) where y != 0 and s - 8 and s - 4
settings enable_optimize_predicate_expression=0" |
grep -o "Aggregating\|Filter column\|Filter column: notEquals(y, 0)\|FUNCTION and(minus(s, 4) :: 2, minus(s, 8) :: 1) -> and(notEquals(y, 0), minus(s, 8), minus(s, 4))"
grep -o "Aggregating\|Filter column\|Filter column: notEquals(y, 0)\|FUNCTION and(minus(s, 8) :: 1, minus(s, 4) :: 2) -> and(notEquals(y, 0), minus(s, 8), minus(s, 4))"
$CLICKHOUSE_CLIENT -q "
select s, y from (
select sum(x) as s, y from (select number as x, number + 1 as y from numbers(10)) group by y
@ -79,7 +79,7 @@ $CLICKHOUSE_CLIENT -q "
select sum(x) as s, y from (select number as x, number + 1 as y from numbers(10)) group by y
) where y != 0 and s != 8 and y - 4
settings enable_optimize_predicate_expression=0" |
grep -o "Aggregating\|Filter column\|Filter column: and(minus(y, 4), notEquals(y, 0))\|ALIAS notEquals(s, 8) :: 1 -> and(notEquals(y, 0), notEquals(s, 8), minus(y, 4))"
grep -o "Aggregating\|Filter column\|Filter column: and(notEquals(y, 0), minus(y, 4))\|ALIAS notEquals(s, 8) :: 1 -> and(notEquals(y, 0), notEquals(s, 8), minus(y, 4))"
$CLICKHOUSE_CLIENT -q "
select s, y from (
select sum(x) as s, y from (select number as x, number + 1 as y from numbers(10)) group by y