Skip to content

Commit

Permalink
🚧 Add OrToUnionRule
Browse files Browse the repository at this point in the history
  • Loading branch information
janetzki committed Aug 6, 2019
1 parent 95a2a62 commit 9a17dc7
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ set(
optimizer/strategy/join_ordering_rule.hpp
optimizer/strategy/predicate_placement_rule.cpp
optimizer/strategy/predicate_placement_rule.hpp
optimizer/strategy/or_to_union_rule.cpp
optimizer/strategy/or_to_union_rule.hpp
optimizer/strategy/predicate_reordering_rule.cpp
optimizer/strategy/predicate_reordering_rule.hpp
optimizer/strategy/predicate_split_up_rule.cpp
Expand Down
3 changes: 3 additions & 0 deletions src/lib/optimizer/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "strategy/index_scan_rule.hpp"
#include "strategy/insert_limit_in_exists_rule.hpp"
#include "strategy/join_ordering_rule.hpp"
#include "strategy/or_to_union_rule.hpp"
#include "strategy/predicate_placement_rule.hpp"
#include "strategy/predicate_reordering_rule.hpp"
#include "strategy/predicate_split_up_rule.hpp"
Expand Down Expand Up @@ -105,6 +106,8 @@ std::shared_ptr<Optimizer> Optimizer::create_default_optimizer() {
// for now we want the PredicateReorderingRule to have the final say on predicate positions
optimizer->add_rule(std::make_unique<PredicatePlacementRule>());

optimizer->add_rule(std::make_unique<OrToUnionRule>());

optimizer->add_rule(std::make_unique<SubqueryToJoinRule>());

optimizer->add_rule(std::make_unique<InsertLimitInExistsRule>());
Expand Down
28 changes: 28 additions & 0 deletions src/lib/optimizer/strategy/or_to_union_rule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "or_to_union_rule.hpp"

//#include <algorithm>
//#include <iostream>
//#include <memory>
//#include <string>
//#include <vector>
//
//#include "constant_mappings.hpp"
//#include "cost_estimation/abstract_cost_estimator.hpp"
//#include "logical_query_plan/abstract_lqp_node.hpp"
//#include "logical_query_plan/lqp_utils.hpp"
//#include "logical_query_plan/predicate_node.hpp"
//#include "optimizer/join_ordering/join_graph.hpp"
//#include "statistics/cardinality_estimation_cache.hpp"
//#include "statistics/cardinality_estimator.hpp"
//#include "statistics/table_statistics.hpp"
//#include "utils/assert.hpp"

namespace opossum {

std::string OrToUnionRule::name() const { return "Or to Union Rule"; }

void OrToUnionRule::apply_to(const std::shared_ptr<AbstractLQPNode>& node) const {
_apply_to_inputs(node);
}

} // namespace opossum
16 changes: 16 additions & 0 deletions src/lib/optimizer/strategy/or_to_union_rule.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "abstract_rule.hpp"
#include "expression/abstract_expression.hpp"
#include "types.hpp"

namespace opossum {

class OrToUnionRule : public AbstractRule {
public:
std::string name() const override;

void apply_to(const std::shared_ptr<AbstractLQPNode>& root) const override;
};

} // namespace opossum
1 change: 1 addition & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ set(
optimizer/strategy/join_ordering_rule_test.cpp
optimizer/strategy/predicate_placement_rule_test.cpp
optimizer/strategy/predicate_reordering_rule_test.cpp
optimizer/strategy/or_to_union_rule_test.cpp
optimizer/strategy/predicate_split_up_rule_test.cpp
optimizer/strategy/strategy_base_test.cpp
optimizer/strategy/strategy_base_test.hpp
Expand Down
112 changes: 112 additions & 0 deletions src/test/optimizer/strategy/or_to_union_rule_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include "gtest/gtest.h"

#include "strategy_base_test.hpp"
#include "testing_assert.hpp"

//#include "expression/expression_functional.hpp"
//#include "expression/lqp_column_expression.hpp"
//#include "logical_query_plan/abstract_lqp_node.hpp"
//#include "logical_query_plan/aggregate_node.hpp"
//#include "logical_query_plan/join_node.hpp"
//#include "logical_query_plan/limit_node.hpp"
//#include "logical_query_plan/mock_node.hpp"
//#include "logical_query_plan/predicate_node.hpp"
//#include "logical_query_plan/projection_node.hpp"
//#include "logical_query_plan/sort_node.hpp"
//#include "logical_query_plan/stored_table_node.hpp"
//#include "logical_query_plan/union_node.hpp"
//#include "logical_query_plan/validate_node.hpp"
//#include "optimizer/strategy/subquery_to_join_rule.hpp"
#include "optimizer/strategy/or_to_union_rule.hpp"

using namespace opossum::expression_functional; // NOLINT

namespace opossum {

class SubqueryToJoinRuleTest : public StrategyBaseTest {
public:
void SetUp() override {
node_a = MockNode::make(
MockNode::ColumnDefinitions{{DataType::Int, "a"}, {DataType::Int, "b"}, {DataType::Int, "c"}}, "a");
a_a = node_a->get_column("a");
a_b = node_a->get_column("b");
a_c = node_a->get_column("c");
a_a_expression = to_expression(a_a);
a_b_expression = to_expression(a_b);
a_c_expression = to_expression(a_c);

node_b = MockNode::make(MockNode::ColumnDefinitions{{DataType::Int, "a"}, {DataType::Int, "b"}}, "b");
b_a = node_b->get_column("a");
b_b = node_b->get_column("b");

node_c = MockNode::make(
MockNode::ColumnDefinitions{{DataType::Int, "a"}, {DataType::Int, "b"}, {DataType::Int, "c"}}, "c");
c_a = node_c->get_column("a");

node_d = MockNode::make(
MockNode::ColumnDefinitions{{DataType::Int, "a"}, {DataType::Int, "b"}, {DataType::Int, "c"}}, "d");
d_a = node_d->get_column("a");
d_b = node_d->get_column("b");
d_c = node_d->get_column("c");

node_e = MockNode::make(
MockNode::ColumnDefinitions{{DataType::Int, "a"}, {DataType::Int, "b"}, {DataType::Int, "c"}}, "e");
e_a = node_e->get_column("a");
e_b = node_e->get_column("b");
e_c = node_e->get_column("c");

lineitem = MockNode::make(MockNode::ColumnDefinitions{{DataType::Int, "extendedprice"},
{DataType::Int, "quantity"},
{DataType::Int, "partkey"},
{DataType::String, "shipdate"},
{DataType::Int, "suppkey"}},
"lineitem");
l_extendedprice = lineitem->get_column("extendedprice");
l_quantity = lineitem->get_column("quantity");
l_partkey = lineitem->get_column("partkey");
l_shipdate = lineitem->get_column("shipdate");
l_suppkey = lineitem->get_column("suppkey");

nation =
MockNode::make(MockNode::ColumnDefinitions{{DataType::Int, "nationkey"}, {DataType::Int, "name"}}, "nation");
n_nationkey = nation->get_column("nationkey");
n_name = nation->get_column("name");

part = MockNode::make(MockNode::ColumnDefinitions{{DataType::Int, "partkey"},
{DataType::String, "brand"},
{DataType::String, "container"},
{DataType::String, "name"}});
p_partkey = part->get_column("partkey");
p_brand = part->get_column("brand");
p_container = part->get_column("container");
p_name = part->get_column("name");

partsupp = MockNode::make(
MockNode::ColumnDefinitions{
{DataType::Int, "availqty"}, {DataType::Int, "partkey"}, {DataType::Int, "suppkey"}},
"partsupp");
ps_availqty = partsupp->get_column("availqty");
ps_partkey = partsupp->get_column("partkey");
ps_suppkey = partsupp->get_column("suppkey");

supplier = MockNode::make(MockNode::ColumnDefinitions{{DataType::Int, "suppkey"},
{DataType::String, "address"},
{DataType::String, "name"},
{DataType::Int, "nationkey"}},
"supplier");
s_suppkey = supplier->get_column("suppkey");
s_address = supplier->get_column("address");
s_name = supplier->get_column("name");
s_nationkey = supplier->get_column("nationkey");

_rule = std::make_shared<SubqueryToJoinRule>();
}

std::shared_ptr<SubqueryToJoinRule> _rule;

std::shared_ptr<MockNode> node_a, node_b, node_c, node_d, node_e, lineitem, nation, part, partsupp, supplier;
LQPColumnReference a_a, a_b, a_c, b_a, b_b, c_a, d_a, d_b, d_c, e_a, e_b, e_c, l_extendedprice, l_quantity, l_partkey,
l_shipdate, l_suppkey, n_nationkey, n_name, p_partkey, p_brand, p_container, p_name, ps_availqty, ps_partkey,
ps_suppkey, s_suppkey, s_address, s_name, s_nationkey;
std::shared_ptr<LQPColumnExpression> a_a_expression, a_b_expression, a_c_expression;
};

0 comments on commit 9a17dc7

Please sign in to comment.