ClickHouse

Форк
0
61 строка · 2.4 Кб
1
#include <Processors/QueryPlan/Optimizations/Optimizations.h>
2
#include <Processors/QueryPlan/FilterStep.h>
3
#include <Processors/QueryPlan/ExpressionStep.h>
4
#include <Processors/QueryPlan/ArrayJoinStep.h>
5
#include <Interpreters/ActionsDAG.h>
6
#include <Interpreters/ArrayJoinAction.h>
7

8
namespace DB::QueryPlanOptimizations
9
{
10

11
size_t tryLiftUpArrayJoin(QueryPlan::Node * parent_node, QueryPlan::Nodes & nodes)
12
{
13
    if (parent_node->children.size() != 1)
14
        return 0;
15

16
    QueryPlan::Node * child_node = parent_node->children.front();
17

18
    auto & parent = parent_node->step;
19
    auto & child = child_node->step;
20
    auto * expression_step = typeid_cast<ExpressionStep *>(parent.get());
21
    auto * filter_step = typeid_cast<FilterStep *>(parent.get());
22
    auto * array_join_step = typeid_cast<ArrayJoinStep *>(child.get());
23

24
    if (!(expression_step || filter_step) || !array_join_step)
25
        return 0;
26

27
    const auto & array_join = array_join_step->arrayJoin();
28
    const auto & expression = expression_step ? expression_step->getExpression()
29
                                              : filter_step->getExpression();
30

31
    auto split_actions = expression->splitActionsBeforeArrayJoin(array_join->columns);
32

33
    /// No actions can be moved before ARRAY JOIN.
34
    if (split_actions.first->trivial())
35
        return 0;
36

37
    auto description = parent->getStepDescription();
38

39
    /// Add new expression step before ARRAY JOIN.
40
    /// Expression/Filter -> ArrayJoin -> Something
41
    auto & node = nodes.emplace_back();
42
    node.children.swap(child_node->children);
43
    child_node->children.emplace_back(&node);
44
    /// Expression/Filter -> ArrayJoin -> node -> Something
45

46
    node.step = std::make_unique<ExpressionStep>(node.children.at(0)->step->getOutputStream(),
47
                                                 std::move(split_actions.first));
48
    node.step->setStepDescription(description);
49
    array_join_step->updateInputStream(node.step->getOutputStream());
50

51
    if (expression_step)
52
        parent = std::make_unique<ExpressionStep>(array_join_step->getOutputStream(), split_actions.second);
53
    else
54
        parent = std::make_unique<FilterStep>(array_join_step->getOutputStream(), split_actions.second,
55
                                              filter_step->getFilterColumnName(), filter_step->removesFilterColumn());
56

57
    parent->setStepDescription(description + " [split]");
58
    return 3;
59
}
60

61
}
62

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.