blob: 79a4f497ff855fb6775a7ff2235e0b2a3433d200 (
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
34
35
36
37
38
39
|
#pragma once
#include <Parsers/IAST.h>
#include <Parsers/ASTFunction.h>
#include <Interpreters/InDepthNodeVisitor.h>
namespace DB
{
/// It converts if-chain to multiIf.
class OptimizeIfChainsVisitor
{
public:
OptimizeIfChainsVisitor() = default;
void visit(ASTPtr & ast);
private:
ASTs ifChain(const ASTPtr & child);
};
/// Replaces multiIf with one condition to if,
/// because it's more efficient.
class OptimizeMultiIfToIfData
{
public:
using TypeToVisit = ASTFunction;
void visit(ASTFunction & function, ASTPtr &)
{
/// 3 args: condition, then branch, else branch.
if (function.name == "multiIf" && (function.arguments && function.arguments->children.size() == 3))
function.name = "if";
}
};
using OptimizeMultiIfToIfMatcher = OneTypeMatcher<OptimizeMultiIfToIfData>;
using OptimizeMultiIfToIfVisitor = InDepthNodeVisitor<OptimizeMultiIfToIfMatcher, true>;
}
|