MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
group.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/limits.h"
14#include "common/lang/vector.h"
15#include "common/lang/unordered_set.h"
16#include "common/lang/memory.h"
17#include "common/log/log.h"
18#include "common/lang/unordered_map.h"
19#include "sql/optimizer/cascade/property_set.h"
20
21class GroupExpr;
22class Memo;
31class Group
32{
33public:
40 Group(int id, GroupExpr *expr, Memo *memo);
41
42 ~Group();
43
49 void add_expr(GroupExpr *expr);
50
58 bool set_expr_cost(GroupExpr *expr, double cost);
59
64
68 const std::vector<GroupExpr *> &get_logical_expressions() const { return logical_expressions_; }
69
73 const std::vector<GroupExpr *> &get_physical_expressions() const { return physical_expressions_; }
74
80 double get_cost_lb() { return -1; }
81
85 void set_explored() { has_explored_ = true; }
86
90 bool has_explored() { return has_explored_; }
91
92 int get_id() const { return id_; }
93
94 GroupExpr *get_logical_expression();
95
96 LogicalProperty *get_logical_prop() { return logical_prop_.get(); }
97
99 void dump() const;
100
101private:
102 int id_;
103
104 std::tuple<double, GroupExpr *> winner_;
105
106 bool has_explored_;
107
108 std::vector<GroupExpr *> logical_expressions_;
109
110 std::vector<GroupExpr *> physical_expressions_;
111
112 unique_ptr<LogicalProperty> logical_prop_ = nullptr;
113};
Definition: group_expr.h:25
A class representing a group within cascade optimizer.
Definition: group.h:32
GroupExpr * get_winner()
Definition: group.cpp:62
bool set_expr_cost(GroupExpr *expr, double cost)
Sets the cost of a given expression in the group.
Definition: group.cpp:51
void set_explored()
Marks the group as explored.
Definition: group.h:85
const std::vector< GroupExpr * > & get_logical_expressions() const
Gets the logical expressions in the group.
Definition: group.h:68
void add_expr(GroupExpr *expr)
Adds an expression to the group.
Definition: group.cpp:41
const std::vector< GroupExpr * > & get_physical_expressions() const
Gets the physical expressions in the group.
Definition: group.h:73
LogicalProperty * get_logical_prop()
dump the group info, for debug
Definition: group.h:96
double get_cost_lb()
Gets the cost lower bound.
Definition: group.h:80
bool has_explored()
Checks if the group has been explored.
Definition: group.h:90
Logical Property, such as the cardinality of logical operator
Definition: property.h:20
: memorization
Definition: memo.h:29