Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Fix for optimizer rule bug #1468

Merged
merged 5 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/optimizer/group_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,21 @@ hash_t GroupExpression::Hash() const {
bool GroupExpression::operator==(const GroupExpression &r) {
bool eq = (op == r.Op());

for (size_t i = 0; i < child_groups.size(); ++i) {
eq = eq && (child_groups[i] == r.child_groups[i]);
auto left_groups = child_groups;
auto right_groups = r.child_groups;

std::sort(left_groups.begin(), left_groups.end());

std::sort(right_groups.begin(), right_groups.end());
for (size_t i = 0; i < left_groups.size(); ++i) {
eq = eq && (left_groups[i] == right_groups[i]);
}

return eq;
}

void GroupExpression::SetRuleExplored(Rule *rule) {
rule_mask_.set(rule->GetRuleIdx()) = true;
rule_mask_.set(rule->GetRuleIdx(), true);
}

bool GroupExpression::HasRuleExplored(Rule *rule) {
Expand Down
2 changes: 0 additions & 2 deletions src/optimizer/memo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ GroupExpression *Memo::InsertExpression(std::shared_ptr<GroupExpression> gexpr,
auto it = group_expressions_.find(gexpr.get());

if (it != group_expressions_.end()) {
PELOTON_ASSERT(target_group == UNDEFINED_GROUP ||
target_group == (*it)->GetGroupID());
gexpr->SetGroupID((*it)->GetGroupID());
return *it;
} else {
Expand Down
27 changes: 27 additions & 0 deletions test/optimizer/optimizer_rule_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,32 @@ TEST_F(OptimizerRuleTests, SimpleAssociativeRuleTest2) {
delete root_context;
}

TEST_F(OptimizerRuleTests, RuleBitmapTest) {
Optimizer optimizer;
auto &memo = optimizer.GetMetadata().memo;

auto dummy_operator = std::make_shared<OperatorExpression>(LogicalGet::make());
auto dummy_group = memo.InsertExpression(optimizer.GetMetadata().MakeGroupExpression(dummy_operator), false);

auto rule1 = new InnerJoinCommutativity();
auto rule2 = new GetToSeqScan();

EXPECT_FALSE(dummy_group->HasRuleExplored(rule1));
EXPECT_FALSE(dummy_group->HasRuleExplored(rule2));

dummy_group->SetRuleExplored(rule1);

EXPECT_TRUE(dummy_group->HasRuleExplored(rule1));
EXPECT_FALSE(dummy_group->HasRuleExplored(rule2));

dummy_group->SetRuleExplored(rule2);

EXPECT_TRUE(dummy_group->HasRuleExplored(rule1));
EXPECT_TRUE(dummy_group->HasRuleExplored(rule2));

delete rule1;
delete rule2;
}

} // namespace test
} // namespace peloton
15 changes: 15 additions & 0 deletions test/sql/testing_sql_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ ResultType TestingSQLUtil::ExecuteSQLQuery(
return status;
}

void PrintPlan(planner::AbstractPlan *plan, int level = 0) {
auto spacing = std::string(level, '\t');
if (plan->GetPlanNodeType() == PlanNodeType::SEQSCAN) {
auto scan = dynamic_cast<planner::AbstractScan *>(plan);
LOG_INFO("%s%s(%s)", spacing.c_str(), scan->GetInfo().c_str(),
scan->GetTable()->GetName().c_str());
} else {
LOG_INFO("%s%s", spacing.c_str(), plan->GetInfo().c_str());
}
for (size_t i = 0; i < plan->GetChildren().size(); i++) {
PrintPlan(plan->GetChildren()[i].get(), level + 1);
}
return;
}

// Execute a SQL query end-to-end with the specific optimizer
ResultType TestingSQLUtil::ExecuteSQLQueryWithOptimizer(
std::unique_ptr<optimizer::AbstractOptimizer> &optimizer,
Expand Down