This repository was archived by the owner on Sep 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 618
/
Copy pathoptimizer.h
164 lines (135 loc) · 5.23 KB
/
optimizer.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//===----------------------------------------------------------------------===//
//
// Peloton
//
// optimizer.h
//
// Identification: src/include/optimizer/optimizer.h
//
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//
#pragma once
#include <memory>
#include "optimizer/abstract_optimizer.h"
#include "optimizer/property_set.h"
#include "optimizer/optimizer_metadata.h"
namespace peloton {
namespace parser {
class SQLStatementList;
class SQLStatement;
}
namespace planner {
class AbstractPlan;
};
namespace optimizer {
class OperatorExpression;
}
namespace concurrency {
class TransactionContext;
}
namespace test {
class OptimizerRuleTests_SimpleAssociativeRuleTest_Test;
class OptimizerRuleTests_SimpleAssociativeRuleTest2_Test;
}
namespace optimizer {
struct UtilPlanStatus {
bool has_plan = false;
std::unique_ptr<planner::AbstractPlan> util_plan;
};
struct QueryInfo {
QueryInfo(std::vector<expression::AbstractExpression *> &exprs,
std::shared_ptr<PropertySet> &props)
: output_exprs(std::move(exprs)), physical_props(props) {}
std::vector<expression::AbstractExpression *> output_exprs;
std::shared_ptr<PropertySet> physical_props;
};
//===--------------------------------------------------------------------===//
// Optimizer
//===--------------------------------------------------------------------===//
class Optimizer : public AbstractOptimizer {
friend class BindingIterator;
friend class GroupBindingIterator;
friend class ::peloton::test::
OptimizerRuleTests_SimpleAssociativeRuleTest_Test;
friend class ::peloton::test::
OptimizerRuleTests_SimpleAssociativeRuleTest2_Test;
public:
Optimizer(const Optimizer &) = delete;
Optimizer &operator=(const Optimizer &) = delete;
Optimizer(Optimizer &&) = delete;
Optimizer &operator=(Optimizer &&) = delete;
Optimizer();
std::shared_ptr<planner::AbstractPlan> BuildPelotonPlanTree(
const std::unique_ptr<parser::SQLStatementList> &parse_tree_list,
concurrency::TransactionContext *txn) override;
void OptimizeLoop(int root_group_id,
std::shared_ptr<PropertySet> required_props);
void Reset() override;
OptimizerMetadata &GetMetadata() { return metadata_; }
/* For test purposes only */
std::shared_ptr<GroupExpression> TestInsertQueryTree(
parser::SQLStatement *tree, concurrency::TransactionContext *txn) {
return InsertQueryTree(tree, txn);
}
/* For test purposes only */
void TestExecuteTaskStack(OptimizerTaskStack &task_stack, int root_group_id,
std::shared_ptr<OptimizeContext> root_context) {
return ExecuteTaskStack(task_stack, root_group_id, root_context);
}
private:
/* HandleUtilStatement - Check and handle Util statment (currently only
*support
*CREATE), set
* tree: a peloton query tree representing a select query
* return: the util plan if it is a util statement, if the sql type
* is not util statements then return with has_plan set to false
*/
UtilPlanStatus HandleUtilStatement(parser::SQLStatement *tree,
concurrency::TransactionContext *txn);
/* TransformQueryTree - create an initial operator tree for the given query
* to be used in performing optimization.
*
* tree: a peloton query tree representing a select query
* return: the root group expression for the inserted query
*/
std::shared_ptr<GroupExpression> InsertQueryTree(
parser::SQLStatement *tree, concurrency::TransactionContext *txn);
/* GetQueryTreeRequiredProperties - get the required physical properties for
* a peloton query tree.
*
* tree: a peloton query tree representing a select query
* return: the set of required physical properties for the query
*/
QueryInfo GetQueryInfo(parser::SQLStatement *tree);
/* ChooseBestPlan - retrieve the lowest cost tree of physical operators for
* the given properties
*
* id: the id of the group to produce the best physical
* requirements: the set of properties the produced physical operator tree
* must satisfy
* output_expr_map: The map of expression generate by this group to their
* corresponding offsets
* return: the lowest cost tree of physical plan nodes
*/
std::unique_ptr<planner::AbstractPlan> ChooseBestPlan(
GroupID id, std::shared_ptr<PropertySet> required_props,
std::vector<expression::AbstractExpression *> required_cols);
/* ExecuteTaskStack - Execute elements of given optimization task stack
* and ensure that we do not go beyond the time limit (unless if one plan has
* not been generated yet)
*
* task_stack: the optimizer's task stack to iterate through
* root_group_id: the root group id to check if we have generated a plan or
*not
* root_context: the OptimizerContext to use that maintains required
*properties
*/
void ExecuteTaskStack(OptimizerTaskStack &task_stack, int root_group_id,
std::shared_ptr<OptimizeContext> root_context);
//////////////////////////////////////////////////////////////////////////////
/// Metadata
OptimizerMetadata metadata_;
};
} // namespace optimizer
} // namespace peloton