quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hakanmemiso...@apache.org
Subject incubator-quickstep git commit: Applied the suggestions and changed Swap optimization to be only applied to inner hash joins.
Date Tue, 02 Aug 2016 12:56:33 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/refactor-hashjoin-probe-build a0905647b -> c36bbc92d


Applied the suggestions and changed Swap optimization to be only applied to inner hash joins.


Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/c36bbc92
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/c36bbc92
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/c36bbc92

Branch: refs/heads/refactor-hashjoin-probe-build
Commit: c36bbc92d70880ed03226ccc72228a424b831961
Parents: a090564
Author: Hakan Memisoglu <hakanmemisoglu@gmail.com>
Authored: Tue Aug 2 07:55:54 2016 -0500
Committer: Hakan Memisoglu <hakanmemisoglu@gmail.com>
Committed: Tue Aug 2 07:55:54 2016 -0500

----------------------------------------------------------------------
 query_optimizer/ExecutionGenerator.cpp     |  4 ++-
 query_optimizer/physical/HashJoin.hpp      | 32 ++++----------------
 query_optimizer/rules/BottomUpRule.hpp     |  3 ++
 query_optimizer/rules/CMakeLists.txt       |  2 +-
 query_optimizer/rules/CollapseProject.cpp  |  5 ++++
 query_optimizer/rules/CollapseProject.hpp  |  1 +
 query_optimizer/rules/SwapProbeBuild.cpp   | 40 ++++++++++---------------
 query_optimizer/rules/SwapProbeBuild.hpp   |  7 +++--
 query_optimizer/rules/UnnestSubqueries.cpp |  4 +++
 query_optimizer/rules/UnnestSubqueries.hpp |  1 +
 query_optimizer/rules/UpdateExpression.cpp |  5 ++++
 query_optimizer/rules/UpdateExpression.hpp |  1 +
 12 files changed, 49 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/ExecutionGenerator.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/ExecutionGenerator.cpp b/query_optimizer/ExecutionGenerator.cpp
index 83c90bd..fb24489 100644
--- a/query_optimizer/ExecutionGenerator.cpp
+++ b/query_optimizer/ExecutionGenerator.cpp
@@ -604,6 +604,8 @@ void ExecutionGenerator::convertHashJoin(const P::HashJoinPtr &physical_plan)
{
   const CatalogRelation *referenced_stored_probe_relation = nullptr;
   const CatalogRelation *referenced_stored_build_relation = nullptr;
 
+  std::size_t build_cardinality = cost_model_->estimateCardinality(build_physical);
+
   bool any_probe_attributes_nullable = false;
   bool any_build_attributes_nullable = false;
 
@@ -727,7 +729,7 @@ void ExecutionGenerator::convertHashJoin(const P::HashJoinPtr &physical_plan)
{
         build_relation->getAttributeById(build_attribute)->getType().getProto());
   }
 
-  hash_table_proto->set_estimated_num_entries(physical_plan->estimated_right_cardinality());
+  hash_table_proto->set_estimated_num_entries(build_cardinality);
 
   // Create three operators.
   const QueryPlan::DAGNodeIndex build_operator_index =

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/physical/HashJoin.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/physical/HashJoin.hpp b/query_optimizer/physical/HashJoin.hpp
index 9c2e9de..988b139 100644
--- a/query_optimizer/physical/HashJoin.hpp
+++ b/query_optimizer/physical/HashJoin.hpp
@@ -107,22 +107,6 @@ class HashJoin : public BinaryJoin {
     return join_type_;
   }
 
-  /**
-   * @return Estimated number of tuples from the right (build)'s side.
-   */
-  std::size_t estimated_right_cardinality() const {
-    return estimated_right_cardinality_;
-  }
-
-  /**
-   * @brief Sets the build side cardinality for using as a hint in a later stage.
-   *
-   * @param estimated_right_cardinality New build side estimated cardinality to be set.
-   */
-  void set_estimated_right_cardinality(const std::size_t estimated_right_cardinality) {
-    estimated_right_cardinality_ = estimated_right_cardinality;
-  }
-
   PhysicalPtr copyWithNewChildren(
       const std::vector<PhysicalPtr> &new_children) const override {
     DCHECK_EQ(children().size(), new_children.size());
@@ -132,8 +116,7 @@ class HashJoin : public BinaryJoin {
                   right_join_attributes_,
                   residual_predicate_,
                   project_expressions(),
-                  join_type_,
-                  estimated_right_cardinality_);
+                  join_type_);
   }
 
   std::vector<expressions::AttributeReferencePtr> getReferencedAttributes() const override;
@@ -162,8 +145,7 @@ class HashJoin : public BinaryJoin {
       const std::vector<expressions::AttributeReferencePtr> &right_join_attributes,
       const expressions::PredicatePtr &residual_predicate,
       const std::vector<expressions::NamedExpressionPtr> &project_expressions,
-      const JoinType join_type,
-      const std::size_t estimated_right_cardinality = 0u) {
+      const JoinType join_type) {
     return HashJoinPtr(
         new HashJoin(left,
                      right,
@@ -171,8 +153,7 @@ class HashJoin : public BinaryJoin {
                      right_join_attributes,
                      residual_predicate,
                      project_expressions,
-                     join_type,
-                     estimated_right_cardinality));
+                     join_type));
   }
 
  protected:
@@ -192,21 +173,18 @@ class HashJoin : public BinaryJoin {
       const std::vector<expressions::AttributeReferencePtr> &right_join_attributes,
       const expressions::PredicatePtr &residual_predicate,
       const std::vector<expressions::NamedExpressionPtr> &project_expressions,
-      const JoinType join_type,
-      const std::size_t estimated_right_cardinality)
+      const JoinType join_type)
       : BinaryJoin(left, right, project_expressions),
         left_join_attributes_(left_join_attributes),
         right_join_attributes_(right_join_attributes),
         residual_predicate_(residual_predicate),
-        join_type_(join_type),
-        estimated_right_cardinality_(estimated_right_cardinality) {
+        join_type_(join_type) {
   }
 
   std::vector<expressions::AttributeReferencePtr> left_join_attributes_;
   std::vector<expressions::AttributeReferencePtr> right_join_attributes_;
   expressions::PredicatePtr residual_predicate_;
   JoinType join_type_;
-  std::size_t estimated_right_cardinality_;
 
   DISALLOW_COPY_AND_ASSIGN(HashJoin);
 };

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/rules/BottomUpRule.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/BottomUpRule.hpp b/query_optimizer/rules/BottomUpRule.hpp
index 0acc199..5831fa0 100644
--- a/query_optimizer/rules/BottomUpRule.hpp
+++ b/query_optimizer/rules/BottomUpRule.hpp
@@ -54,6 +54,7 @@ class BottomUpRule : public Rule<TreeType> {
   TreeNodePtr apply(const TreeNodePtr &tree) override {
     DCHECK(tree != nullptr);
 
+    init(tree);
     std::vector<std::shared_ptr<const TreeType>> new_children;
     bool has_changed_children = false;
     for (const std::shared_ptr<const TreeType> &child : tree->children()) {
@@ -80,6 +81,8 @@ class BottomUpRule : public Rule<TreeType> {
    */
   virtual TreeNodePtr applyToNode(const TreeNodePtr &node) = 0;
 
+  virtual void init(const TreeNodePtr &node) = 0;
+
  private:
   DISALLOW_COPY_AND_ASSIGN(BottomUpRule);
 };

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/rules/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/CMakeLists.txt b/query_optimizer/rules/CMakeLists.txt
index 73d7e38..04a9814 100644
--- a/query_optimizer/rules/CMakeLists.txt
+++ b/query_optimizer/rules/CMakeLists.txt
@@ -129,7 +129,7 @@ target_link_libraries(quickstep_queryoptimizer_rules_StarSchemaHashJoinOrderOpti
                       quickstep_queryoptimizer_rules_Rule
                       quickstep_utility_Macros)
 target_link_libraries(quickstep_queryoptimizer_rules_SwapProbeBuild
-                      quickstep_queryoptimizer_costmodel_StarSchemaSimpleCostModel
+                      quickstep_queryoptimizer_costmodel_SimpleCostModel
                       quickstep_queryoptimizer_expressions_AttributeReference
                       quickstep_queryoptimizer_physical_HashJoin
                       quickstep_queryoptimizer_physical_PatternMatcher

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/rules/CollapseProject.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/CollapseProject.cpp b/query_optimizer/rules/CollapseProject.cpp
index 6f2fa13..62567e8 100644
--- a/query_optimizer/rules/CollapseProject.cpp
+++ b/query_optimizer/rules/CollapseProject.cpp
@@ -54,5 +54,10 @@ L::LogicalPtr CollapseProject::applyToNode(const L::LogicalPtr &input)
{
   return input;
 }
 
+void CollapseProject::init(const L::LogicalPtr &input) {
+  // Do nothing.
+  return;
+}
+
 }  // namespace optimizer
 }  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/rules/CollapseProject.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/CollapseProject.hpp b/query_optimizer/rules/CollapseProject.hpp
index db45864..528e3c7 100644
--- a/query_optimizer/rules/CollapseProject.hpp
+++ b/query_optimizer/rules/CollapseProject.hpp
@@ -43,6 +43,7 @@ class CollapseProject : public BottomUpRule<logical::Logical> {
 
  protected:
   logical::LogicalPtr applyToNode(const logical::LogicalPtr &input) override;
+  void init(const logical::LogicalPtr &input) override;
 
  private:
   DISALLOW_COPY_AND_ASSIGN(CollapseProject);

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/rules/SwapProbeBuild.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/SwapProbeBuild.cpp b/query_optimizer/rules/SwapProbeBuild.cpp
index a24979f..86c6424 100644
--- a/query_optimizer/rules/SwapProbeBuild.cpp
+++ b/query_optimizer/rules/SwapProbeBuild.cpp
@@ -18,17 +18,12 @@ namespace optimizer {
 P::PhysicalPtr SwapProbeBuild::applyToNode(const P::PhysicalPtr &input) {
   P::HashJoinPtr hash_join;
 
-  if (P::SomeHashJoin::MatchesWithConditionalCast(input, &hash_join)) {
+  if (P::SomeHashJoin::MatchesWithConditionalCast(input, &hash_join)
+      && hash_join->join_type() == P::HashJoin::JoinType::kInnerJoin) {
     P::PhysicalPtr left = hash_join->left();
     P::PhysicalPtr right = hash_join->right();
 
-    P::TopLevelPlanPtr top_level;
-    if (P::SomeTopLevelPlan::MatchesWithConditionalCast(input, &top_level)) {
-      cost_model_.reset(new C::StarSchemaSimpleCostModel(top_level->shared_subplans()));
-    } else {
-      std::vector<P::PhysicalPtr> plans = {input};
-      cost_model_.reset(new C::StarSchemaSimpleCostModel(plans));
-    }
+
 
     std::size_t left_cardinality = cost_model_->estimateCardinality(left);
     std::size_t right_cardinality = cost_model_->estimateCardinality(right);
@@ -43,30 +38,27 @@ P::PhysicalPtr SwapProbeBuild::applyToNode(const P::PhysicalPtr &input)
{
                                                   left_join_attributes,
                                                   hash_join->residual_predicate(),
                                                   hash_join->project_expressions(),
-                                                  hash_join->join_type(),
-                                                  left_cardinality);
+                                                  hash_join->join_type());
       LOG_APPLYING_RULE(input, output);
       return output;
     }
-    else {
-      P::PhysicalPtr output = P::HashJoin::Create(left,
-                                                  right,
-                                                  hash_join->left_join_attributes(),
-                                                  hash_join->right_join_attributes(),
-                                                  hash_join->residual_predicate(),
-                                                  hash_join->project_expressions(),
-                                                  hash_join->join_type(),
-                                                  right_cardinality);
-      // Since we did not apply the swap logic, we will not report it to the log.
-      // However we also did not ignored the rule completely, therefore we will not
-      // log that we ignored the rule.
-      return output;
-    }
   }
 
   LOG_IGNORING_RULE(input);
   return input;
 }
 
+void SwapProbeBuild::init(const P::PhysicalPtr &input) {
+  if (cost_model_ == nullptr) {
+    P::TopLevelPlanPtr top_level;
+    if (P::SomeTopLevelPlan::MatchesWithConditionalCast(input, &top_level)) {
+      cost_model_.reset(new C::SimpleCostModel(top_level->shared_subplans()));
+    } else {
+      std::vector<P::PhysicalPtr> plans = {input};
+      cost_model_.reset(new C::SimpleCostModel(plans));
+    }
+  }
+}
+
 }  // namespace optimizer
 }  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/rules/SwapProbeBuild.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/SwapProbeBuild.hpp b/query_optimizer/rules/SwapProbeBuild.hpp
index 5cc8cf9..4f7fe38 100644
--- a/query_optimizer/rules/SwapProbeBuild.hpp
+++ b/query_optimizer/rules/SwapProbeBuild.hpp
@@ -6,7 +6,7 @@
 #include "query_optimizer/physical/Physical.hpp"
 #include "query_optimizer/rules/Rule.hpp"
 #include "query_optimizer/rules/BottomUpRule.hpp"
-#include "query_optimizer/cost_model/StarSchemaSimpleCostModel.hpp"
+#include "query_optimizer/cost_model/SimpleCostModel.hpp"
 #include "utility/Macros.hpp"
 
 namespace quickstep {
@@ -33,11 +33,12 @@ class SwapProbeBuild : public BottomUpRule<P::Physical> {
 
  protected:
   P::PhysicalPtr applyToNode(const P::PhysicalPtr &input) override;
+  void init(const P::PhysicalPtr &input) override;
 
  private:
-  DISALLOW_COPY_AND_ASSIGN(SwapProbeBuild);
+  std::unique_ptr<C::SimpleCostModel> cost_model_;
 
-  std::unique_ptr<C::StarSchemaSimpleCostModel> cost_model_;
+  DISALLOW_COPY_AND_ASSIGN(SwapProbeBuild);
 };
 
 }  // namespace optimizer

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/rules/UnnestSubqueries.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/UnnestSubqueries.cpp b/query_optimizer/rules/UnnestSubqueries.cpp
index d22ab8e..015e959 100644
--- a/query_optimizer/rules/UnnestSubqueries.cpp
+++ b/query_optimizer/rules/UnnestSubqueries.cpp
@@ -790,5 +790,9 @@ E::ExpressionPtr DeOuterAttributeReference::applyToNode(const E::ExpressionPtr
&
   return input;
 }
 
+void DeOuterAttributeReference::init(const E::ExpressionPtr &input) {
+  return;
+}
+
 }  // namespace optimizer
 }  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/rules/UnnestSubqueries.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/UnnestSubqueries.hpp b/query_optimizer/rules/UnnestSubqueries.hpp
index d51dfd5..83c30b3 100644
--- a/query_optimizer/rules/UnnestSubqueries.hpp
+++ b/query_optimizer/rules/UnnestSubqueries.hpp
@@ -219,6 +219,7 @@ class DeOuterAttributeReference : public BottomUpRule<expressions::Expression>
{
 
  protected:
   expressions::ExpressionPtr applyToNode(const expressions::ExpressionPtr &input) override;
+  void init(const expressions::ExpressionPtr &input) override;
 
  private:
   const bool allow_outer_reference_;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/rules/UpdateExpression.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/UpdateExpression.cpp b/query_optimizer/rules/UpdateExpression.cpp
index b99178c..25d86cf 100644
--- a/query_optimizer/rules/UpdateExpression.cpp
+++ b/query_optimizer/rules/UpdateExpression.cpp
@@ -48,5 +48,10 @@ E::ExpressionPtr UpdateExpression::applyToNode(const E::ExpressionPtr &input)
{
   return input;
 }
 
+void UpdateExpression::init(const E::ExpressionPtr &input) {
+  // Do nothing.
+  return;
+}
+
 }  // namespace optimizer
 }  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c36bbc92/query_optimizer/rules/UpdateExpression.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/UpdateExpression.hpp b/query_optimizer/rules/UpdateExpression.hpp
index 0c9fe5a..e12c24e 100644
--- a/query_optimizer/rules/UpdateExpression.hpp
+++ b/query_optimizer/rules/UpdateExpression.hpp
@@ -53,6 +53,7 @@ class UpdateExpression : public BottomUpRule<expressions::Expression>
{
 
  protected:
   expressions::ExpressionPtr applyToNode(const expressions::ExpressionPtr &input) override;
+  void init(const expressions::ExpressionPtr &input) override;
 
  private:
   const std::unordered_map<expressions::ExprId, expressions::ExpressionPtr> &substitution_map_;


Mime
View raw message