MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
全部  文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
group_expr.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 "common/lang/bitset.h"
14#include "common/log/log.h"
15#include "common/lang/unordered_map.h"
16#include "sql/operator/operator_node.h"
17#include "sql/optimizer/cascade/rules.h"
18#include "sql/optimizer/cascade/property_set.h"
19
20// TODO: rename to m_expr(in columbia)?
21/* GroupExpr used to represent a particular logical or physical
22 * operator expression.
23 */
25{
26public:
31 GroupExpr(OperatorNode *contents, std::vector<int> &&child_groups)
32 : group_id_(-1), contents_(contents), child_groups_(child_groups)
33 {}
34
35 ~GroupExpr() {}
36
37 int get_group_id() const { return group_id_; }
38
39 void set_group_id(int id) { group_id_ = id; }
40
41 const vector<int> &get_child_group_ids() const { return child_groups_; }
42
43 int get_child_group_id(int child_idx) const
44 {
45 ASSERT(child_idx >= 0 && static_cast<size_t>(child_idx) < child_groups_.size(),
46 "child_idx is out of bounds");
47 return child_groups_[child_idx];
48 }
49
50 OperatorNode *get_op() { return contents_; }
51
52 double get_cost() const { return lowest_cost_; }
53
54 void set_local_cost(double cost)
55 {
56 if (cost < lowest_cost_) {
57 lowest_cost_ = cost;
58 }
59 }
60
61 // TODO
62 uint64_t hash() const;
63
64 bool operator==(const GroupExpr &r) const
65 {
66 return (*contents_ == *(r.contents_)) && (child_groups_ == r.child_groups_);
67 }
68
69 void set_rule_explored(Rule *rule) { rule_mask_.set(rule->get_rule_idx(), true); }
70
71 bool rule_explored(Rule *rule) { return rule_mask_.test(rule->get_rule_idx()); }
72
73 size_t get_children_groups_size() const { return child_groups_.size(); }
74
75 void dump() const;
76
77private:
78 int group_id_{};
79
80 OperatorNode *contents_{};
81
82 std::vector<int> child_groups_;
83
84 std::bitset<static_cast<uint32_t>(RuleType::NUM_RULES)> rule_mask_;
85
86 double lowest_cost_ = std::numeric_limits<double>::max();
87};
Definition: group_expr.h:25
GroupExpr(OperatorNode *contents, std::vector< int > &&child_groups)
Definition: group_expr.h:31
Definition: operator_node.h:69
Definition: rules.h:80
uint32_t get_rule_idx()
Definition: rules.h:107