You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by ha...@apache.org on 2016/08/01 22:25:23 UTC

[2/2] incubator-quickstep git commit: Added a field in Physical HashJoin to save right(build) side estimated cardinality.

Added a field in Physical HashJoin to save right(build) side estimated cardinality.


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

Branch: refs/heads/refactor-hashjoin-probe-build
Commit: a0905647b783873d8c5ff7b5f17c6fa66f357e36
Parents: 372902d
Author: Hakan Memisoglu <ha...@gmail.com>
Authored: Mon Aug 1 17:24:47 2016 -0500
Committer: Hakan Memisoglu <ha...@gmail.com>
Committed: Mon Aug 1 17:24:47 2016 -0500

----------------------------------------------------------------------
 query_optimizer/ExecutionGenerator.cpp   |  2 +-
 query_optimizer/physical/HashJoin.hpp    | 33 +++++++++++++++++++++++----
 query_optimizer/rules/SwapProbeBuild.cpp | 17 +++++++++++++-
 3 files changed, 45 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/a0905647/query_optimizer/ExecutionGenerator.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/ExecutionGenerator.cpp b/query_optimizer/ExecutionGenerator.cpp
index cd6a7c6..83c90bd 100644
--- a/query_optimizer/ExecutionGenerator.cpp
+++ b/query_optimizer/ExecutionGenerator.cpp
@@ -727,7 +727,7 @@ void ExecutionGenerator::convertHashJoin(const P::HashJoinPtr &physical_plan) {
         build_relation->getAttributeById(build_attribute)->getType().getProto());
   }
 
-  hash_table_proto->set_estimated_num_entries(build_cardinality);
+  hash_table_proto->set_estimated_num_entries(physical_plan->estimated_right_cardinality());
 
   // Create three operators.
   const QueryPlan::DAGNodeIndex build_operator_index =

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/a0905647/query_optimizer/physical/HashJoin.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/physical/HashJoin.hpp b/query_optimizer/physical/HashJoin.hpp
index b904b5f..9c2e9de 100644
--- a/query_optimizer/physical/HashJoin.hpp
+++ b/query_optimizer/physical/HashJoin.hpp
@@ -20,6 +20,7 @@
 #ifndef QUICKSTEP_QUERY_OPTIMIZER_PHYSICAL_HASHJOIN_HPP_
 #define QUICKSTEP_QUERY_OPTIMIZER_PHYSICAL_HASHJOIN_HPP_
 
+#include <cstddef>
 #include <memory>
 #include <string>
 #include <type_traits>
@@ -106,6 +107,22 @@ 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());
@@ -115,7 +132,8 @@ class HashJoin : public BinaryJoin {
                   right_join_attributes_,
                   residual_predicate_,
                   project_expressions(),
-                  join_type_);
+                  join_type_,
+                  estimated_right_cardinality_);
   }
 
   std::vector<expressions::AttributeReferencePtr> getReferencedAttributes() const override;
@@ -144,7 +162,8 @@ 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 JoinType join_type,
+      const std::size_t estimated_right_cardinality = 0u) {
     return HashJoinPtr(
         new HashJoin(left,
                      right,
@@ -152,7 +171,8 @@ class HashJoin : public BinaryJoin {
                      right_join_attributes,
                      residual_predicate,
                      project_expressions,
-                     join_type));
+                     join_type,
+                     estimated_right_cardinality));
   }
 
  protected:
@@ -172,18 +192,21 @@ 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 JoinType join_type,
+      const std::size_t estimated_right_cardinality)
       : 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) {
+        join_type_(join_type),
+        estimated_right_cardinality_(estimated_right_cardinality) {
   }
 
   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/a0905647/query_optimizer/rules/SwapProbeBuild.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/SwapProbeBuild.cpp b/query_optimizer/rules/SwapProbeBuild.cpp
index 63347e9..a24979f 100644
--- a/query_optimizer/rules/SwapProbeBuild.cpp
+++ b/query_optimizer/rules/SwapProbeBuild.cpp
@@ -43,10 +43,25 @@ P::PhysicalPtr SwapProbeBuild::applyToNode(const P::PhysicalPtr &input) {
                                                   left_join_attributes,
                                                   hash_join->residual_predicate(),
                                                   hash_join->project_expressions(),
-                                                  hash_join->join_type());
+                                                  hash_join->join_type(),
+                                                  left_cardinality);
       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);