blob: e98386a6ee9fbf4b5f10551df9f0a4f76dc41412 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include <Processors/QueryPlan/Optimizations/Optimizations.h>
#include <Processors/QueryPlan/ExpressionStep.h>
#include <Processors/QueryPlan/FilterStep.h>
#include <Processors/QueryPlan/SourceStepWithFilter.h>
#include <deque>
namespace DB::QueryPlanOptimizations
{
void optimizePrimaryKeyCondition(const Stack & stack)
{
const auto & frame = stack.back();
auto * source_step_with_filter = dynamic_cast<SourceStepWithFilter *>(frame.node->step.get());
if (!source_step_with_filter)
return;
for (auto iter = stack.rbegin() + 1; iter != stack.rend(); ++iter)
{
if (auto * filter_step = typeid_cast<FilterStep *>(iter->node->step.get()))
source_step_with_filter->addFilter(filter_step->getExpression(), filter_step->getFilterColumnName());
/// Note: actually, plan optimizations merge Filter and Expression steps.
/// Ideally, chain should look like (Expression -> ...) -> (Filter -> ...) -> ReadFromStorage,
/// So this is likely not needed.
else if (typeid_cast<ExpressionStep *>(iter->node->step.get()))
continue;
else
break;
}
}
}
|