MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
operator_node.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11#pragma once
12
13#include <stdint.h>
14#include "common/lang/vector.h"
15#include "common/lang/memory.h"
16#include "sql/optimizer/cascade/property.h"
17#include "sql/optimizer/cascade/cost_model.h"
21enum class OpType
22{
23 UNDEFINED = 0,
24
25 // Special wildcard
26 LEAF,
27
28 // Logical Operators
29 LOGICALGET,
30 LOGICALCALCULATE,
31 LOGICALGROUPBY,
32 LOGICALPROJECTION,
33 LOGICALFILTER,
34 LOGICALINNERJOIN,
35 LOGICALINSERT,
36 LOGICALDELETE,
37 LOGICALUPDATE,
38 LOGICALLIMIT,
39 LOGICALANALYZE,
40 LOGICALEXPLAIN,
41 // Separation of logical and physical operators
42 LOGICALPHYSICALDELIMITER,
43
44 // Physical Operators
45 EXPLAIN,
46 CALCULATE,
47 SEQSCAN,
48 INDEXSCAN,
49 ORDERBY,
50 LIMIT,
51 INNERINDEXJOIN,
52 INNERNLJOIN,
53 INNERHASHJOIN,
54 PROJECTION,
55 INSERT,
56 DELETE,
57 UPDATE,
58 AGGREGATE,
59 HASHGROUPBY,
60 ANALYZE,
61 FILTER,
62 SCALARGROUPBY
63};
64
65// TODO: OperatorNode is the abstrace class of logical/physical operator
66// in cascade there is EXPR to include OperatorNode and OperatorNode children
67// so here remove genral_children.
69{
70public:
71 virtual ~OperatorNode() = default;
75 // virtual std::string get_name() const = 0;
76
80 virtual OpType get_op_type() const { return OpType::UNDEFINED; }
81
85 virtual bool is_physical() const = 0;
86
90 virtual bool is_logical() const = 0;
91
95 virtual uint64_t hash() const { return std::hash<int>()(static_cast<int>(get_op_type())); }
96 virtual bool operator==(const OperatorNode &other) const
97 {
98 if (get_op_type() != other.get_op_type())
99 return false;
100 if (general_children_.size() != other.general_children_.size())
101 return false;
102
103 for (size_t idx = 0; idx < general_children_.size(); idx++) {
104 auto &child = general_children_[idx];
105 auto &other_child = other.general_children_[idx];
106
107 if (*child != *other_child)
108 return false;
109 }
110 return true;
111 }
117 virtual unique_ptr<LogicalProperty> find_log_prop(const vector<LogicalProperty *> &log_props) { return nullptr; }
118
131 virtual double calculate_cost(LogicalProperty *prop, const vector<LogicalProperty *> &child_log_props, CostModel *cm)
132 {
133 return 0.0;
134 }
135
136 void add_general_child(OperatorNode *child) { general_children_.push_back(child); }
137
138 vector<OperatorNode *> &get_general_children() { return general_children_; }
139
140protected:
141 // TODO: refactor
142 // cascade optimizer 中使用,为了logical/physical operator 可以统一在 cascade 中迭代
143 vector<OperatorNode *> general_children_;
144};
cost model in cost-based optimization(CBO)
Definition: cost_model.h:19
Logical Property, such as the cardinality of logical operator
Definition: property.h:20
Definition: operator_node.h:69
virtual double calculate_cost(LogicalProperty *prop, const vector< LogicalProperty * > &child_log_props, CostModel *cm)
Calculates the cost of a logical operation.
Definition: operator_node.h:131
virtual OpType get_op_type() const
Definition: operator_node.h:80
virtual bool is_physical() const =0
virtual unique_ptr< LogicalProperty > find_log_prop(const vector< LogicalProperty * > &log_props)
Generate the logical property of the operator node using the input logical properties.
Definition: operator_node.h:117
virtual bool is_logical() const =0
virtual uint64_t hash() const
Definition: operator_node.h:95