ClickHouse

Форк
0
/
optimizePrimaryKeyCondition.cpp 
43 строки · 1.6 Кб
1
#include <Processors/QueryPlan/Optimizations/Optimizations.h>
2
#include <Processors/QueryPlan/ExpressionStep.h>
3
#include <Processors/QueryPlan/FilterStep.h>
4
#include <Processors/QueryPlan/ReadFromMergeTree.h>
5
#include <Processors/QueryPlan/SourceStepWithFilter.h>
6

7
namespace DB::QueryPlanOptimizations
8
{
9

10
void optimizePrimaryKeyCondition(const Stack & stack)
11
{
12
    const auto & frame = stack.back();
13

14
    auto * source_step_with_filter = dynamic_cast<SourceStepWithFilter *>(frame.node->step.get());
15
    if (!source_step_with_filter)
16
        return;
17

18
    const auto & storage_prewhere_info = source_step_with_filter->getPrewhereInfo();
19
    if (storage_prewhere_info)
20
    {
21
        source_step_with_filter->addFilter(storage_prewhere_info->prewhere_actions, storage_prewhere_info->prewhere_column_name);
22
        if (storage_prewhere_info->row_level_filter)
23
            source_step_with_filter->addFilter(storage_prewhere_info->row_level_filter, storage_prewhere_info->row_level_column_name);
24
    }
25

26
    for (auto iter = stack.rbegin() + 1; iter != stack.rend(); ++iter)
27
    {
28
        if (auto * filter_step = typeid_cast<FilterStep *>(iter->node->step.get()))
29
            source_step_with_filter->addFilter(filter_step->getExpression(), filter_step->getFilterColumnName());
30

31
        /// Note: actually, plan optimizations merge Filter and Expression steps.
32
        /// Ideally, chain should look like (Expression -> ...) -> (Filter -> ...) -> ReadFromStorage,
33
        /// So this is likely not needed.
34
        else if (typeid_cast<ExpressionStep *>(iter->node->step.get()))
35
            continue;
36
        else
37
            break;
38
    }
39

40
    source_step_with_filter->applyFilters();
41
}
42

43
}
44

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

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

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

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