Skip to content

Commit

Permalink
Add enable_projection_pushdown configuration for Optimizer
Browse files Browse the repository at this point in the history
Signed-off-by: Wenbo Li <lwb21@mails.tsinghua.edu.cn>
  • Loading branch information
hnjylwb committed Mar 23, 2024
1 parent 6cc46c7 commit 2ebbe31
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/database/database_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void DatabaseEngine::ExecuteSql(const std::string &sql, ResultWriter &writer, co

if (enable_optimizer_) {
// 查询计划优化
Optimizer optimizer(*catalog_, join_order_algorithm_);
Optimizer optimizer(*catalog_, join_order_algorithm_, enable_projection_pushdown_);
plan = optimizer.Optimize(plan);
}

Expand Down Expand Up @@ -504,7 +504,7 @@ void DatabaseEngine::Explain(const ExplainStatement &stmt, ResultWriter &writer)
}

if (enable_optimizer_) {
Optimizer optimizer(*catalog_, join_order_algorithm_);
Optimizer optimizer(*catalog_, join_order_algorithm_, enable_projection_pushdown_);
plan = optimizer.Optimize(plan);
}

Expand All @@ -525,6 +525,8 @@ void DatabaseEngine::VariableSet(const Connection &connection, const VariableSet
force_join_ = String2ForceJoin(stmt.value_);
} else if (stmt.variable_ == "enable_optimizer") {
enable_optimizer_ = String2Bool(stmt.value_);
} else if (stmt.variable_ == "enable_projection_pushdown") {
enable_projection_pushdown_ = String2Bool(stmt.value_);
} else if (stmt.variable_ == "deadlock") {
lock_manager_->SetDeadLockType(String2DeadlockType(stmt.value_));
}
Expand Down
1 change: 1 addition & 0 deletions src/database/database_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class DatabaseEngine {
ForceJoin force_join_ = ForceJoin::NONE;
JoinOrderAlgorithm join_order_algorithm_ = DEFAULT_JOIN_ORDER_ALGORITHM;
bool enable_optimizer_ = true;
bool enable_projection_pushdown_ = false;

bool crashed_ = false;
};
Expand Down
12 changes: 7 additions & 5 deletions src/optimizer/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace huadb {

Optimizer::Optimizer(Catalog &catalog, JoinOrderAlgorithm join_order_algorithm)
: catalog_(catalog), join_order_algorithm_(join_order_algorithm) {}
Optimizer::Optimizer(Catalog &catalog, JoinOrderAlgorithm join_order_algorithm, bool enable_projection_pushdown)
: catalog_(catalog),
join_order_algorithm_(join_order_algorithm),
enable_projection_pushdown_(enable_projection_pushdown) {}

std::shared_ptr<Operator> Optimizer::Optimize(std::shared_ptr<Operator> plan) {
plan = SplitPredicates(plan);
Expand Down Expand Up @@ -54,12 +56,12 @@ std::shared_ptr<Operator> Optimizer::PushDownProjection(std::shared_ptr<Operator
}

std::shared_ptr<Operator> Optimizer::PushDownJoin(std::shared_ptr<Operator> plan) {
for (auto &child : plan->children_) {
child = PushDown(child);
}
// 判断当前查询计划树的连接谓词是否使用当前的 NestedLoopJoin 节点的列
// 如果有,将连接谓词添加到当前的 NestedLoopJoin 节点的 join_condition_ 中
// LAB 5 BEGIN
for (auto &child : plan->children_) {
child = PushDown(child);
}
return plan;
}

Expand Down
3 changes: 2 additions & 1 deletion src/optimizer/optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static constexpr JoinOrderAlgorithm DEFAULT_JOIN_ORDER_ALGORITHM = JoinOrderAlgo

class Optimizer {
public:
Optimizer(Catalog &catalog, JoinOrderAlgorithm join_order_algorithm);
Optimizer(Catalog &catalog, JoinOrderAlgorithm join_order_algorithm, bool enable_projection_pushdown);
std::shared_ptr<Operator> Optimize(std::shared_ptr<Operator> plan);

private:
Expand All @@ -24,6 +24,7 @@ class Optimizer {
std::shared_ptr<Operator> ReorderJoin(std::shared_ptr<Operator> plan);

JoinOrderAlgorithm join_order_algorithm_;
bool enable_projection_pushdown_;
Catalog &catalog_;
};

Expand Down

0 comments on commit 2ebbe31

Please sign in to comment.