aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/core/yql_cost_function.h
blob: 51479f1fb12a1887310d2e0f113ef16d2d4cd178 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once

#include "yql_statistics.h"

#include <util/generic/hash.h>
#include <util/generic/vector.h>
#include <util/generic/string.h>

#include <set>

/**
 * The cost function for cost based optimizer currently consists of methods for computing
 * both the cost and cardinalities of individual plan operators
*/
namespace NYql {

struct IProviderContext;

enum class EJoinAlgoType {
    Undefined,
    LookupJoin,
    LookupJoinReverse,
    MapJoin,
    GraceJoin,
    StreamLookupJoin, //Right part can be updated during an operation. Used mainly for joining streams with lookup tables. Currently impplemented in Dq by LookupInputTransform
    MergeJoin  // To be used in YT
};

//StreamLookupJoin is not a subject for CBO and not not included here
static constexpr auto AllJoinAlgos = { EJoinAlgoType::LookupJoin, EJoinAlgoType::LookupJoinReverse, EJoinAlgoType::MapJoin, EJoinAlgoType::GraceJoin, EJoinAlgoType::MergeJoin };

namespace NDq {

/**
 * Join column is a struct that records the relation label and
 * attribute name, used in join conditions
*/
struct TJoinColumn {
    TString RelName{};
    TString AttributeName{};
    TString AttributeNameWithAliases{};
    std::optional<ui32> EquivalenceClass{};
    bool IsConstant = false;

    TJoinColumn(TString relName, TString attributeName) : 
        RelName(relName),
        AttributeName(attributeName),
        AttributeNameWithAliases(attributeName) {}

    bool operator == (const TJoinColumn& other) const {
        return RelName == other.RelName && AttributeName == other.AttributeName;
    }

    struct THashFunction
    {
        size_t operator()(const TJoinColumn& c) const
        {
            return THash<TString>{}(c.RelName) ^ THash<TString>{}(c.AttributeName);
        }
    };
};

bool operator < (const TJoinColumn& c1, const TJoinColumn& c2);

}  // namespace NDq

}  // namespace NYql