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: Initial changes.
Date Tue, 26 Jul 2016 18:45:23 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/selection-probe-fuse [created] 590b6f012


Initial changes.


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

Branch: refs/heads/selection-probe-fuse
Commit: 590b6f0121eae695743a213353a422951d77e572
Parents: 2b78380
Author: Hakan Memisoglu <hakanmemisoglu@apache.org>
Authored: Tue Jul 26 13:44:49 2016 -0500
Committer: Hakan Memisoglu <hakanmemisoglu@apache.org>
Committed: Tue Jul 26 13:44:49 2016 -0500

----------------------------------------------------------------------
 query_optimizer/ExecutionGenerator.cpp    |  3 +-
 query_optimizer/PhysicalGenerator.cpp     |  2 ++
 query_optimizer/physical/HashJoin.hpp     |  2 ++
 query_optimizer/rules/CMakeLists.txt      |  1 +
 query_optimizer/rules/FuseJoinSelect.cpp  | 41 ++++++++++++++++++++++++++
 query_optimizer/rules/FuseJoinSelect.hpp  | 26 ++++++++++++++++
 relational_operators/HashJoinOperator.cpp | 41 +++++++++++++++++++++-----
 relational_operators/HashJoinOperator.hpp | 29 +++++++++++++-----
 8 files changed, 130 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/590b6f01/query_optimizer/ExecutionGenerator.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/ExecutionGenerator.cpp b/query_optimizer/ExecutionGenerator.cpp
index 43d63f9..ac8dc62 100644
--- a/query_optimizer/ExecutionGenerator.cpp
+++ b/query_optimizer/ExecutionGenerator.cpp
@@ -801,7 +801,8 @@ void ExecutionGenerator::convertHashJoin(const P::HashJoinPtr &physical_plan)
{
               residual_predicate_index,
               project_expressions_group_index,
               is_selection_on_build.get(),
-              join_type));
+              join_type,
+              nullptr /* filter predicate */));
   insert_destination_proto->set_relational_op_index(join_operator_index);
 
   const QueryPlan::DAGNodeIndex destroy_operator_index =

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/590b6f01/query_optimizer/PhysicalGenerator.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/PhysicalGenerator.cpp b/query_optimizer/PhysicalGenerator.cpp
index 75a7bc9..731c17d 100644
--- a/query_optimizer/PhysicalGenerator.cpp
+++ b/query_optimizer/PhysicalGenerator.cpp
@@ -99,6 +99,8 @@ P::PhysicalPtr PhysicalGenerator::optimizePlan() {
   }
   rules.emplace_back(new PruneColumns());
 
+  rules.emplace_back(new Fuse());
+
   for (std::unique_ptr<Rule<P::Physical>> &rule : rules) {
     physical_plan_ = rule->apply(physical_plan_);
     DVLOG(5) << "After applying rule " << rule->getName() << ":\n"

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/590b6f01/query_optimizer/physical/HashJoin.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/physical/HashJoin.hpp b/query_optimizer/physical/HashJoin.hpp
index b904b5f..6761ac6 100644
--- a/query_optimizer/physical/HashJoin.hpp
+++ b/query_optimizer/physical/HashJoin.hpp
@@ -185,6 +185,8 @@ class HashJoin : public BinaryJoin {
   expressions::PredicatePtr residual_predicate_;
   JoinType join_type_;
 
+  expressions::PredicatePtr filter_predicate_;
+
   DISALLOW_COPY_AND_ASSIGN(HashJoin);
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/590b6f01/query_optimizer/rules/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/CMakeLists.txt b/query_optimizer/rules/CMakeLists.txt
index 1990174..4c064e9 100644
--- a/query_optimizer/rules/CMakeLists.txt
+++ b/query_optimizer/rules/CMakeLists.txt
@@ -20,6 +20,7 @@ add_subdirectory(tests)
 # Declare micro-libs:
 add_library(quickstep_queryoptimizer_rules_BottomUpRule ../../empty_src.cpp BottomUpRule.hpp)
 add_library(quickstep_queryoptimizer_rules_CollapseProject CollapseProject.cpp CollapseProject.hpp)
+add_library(quickstep_queryoptimizer_rules_FuseJoinSelect FuseJoinSelect.cpp FuseJoinSelect.hpp)
 add_library(quickstep_queryoptimizer_rules_GenerateJoins GenerateJoins.cpp GenerateJoins.hpp)
 add_library(quickstep_queryoptimizer_rules_PruneColumns PruneColumns.cpp PruneColumns.hpp)
 add_library(quickstep_queryoptimizer_rules_PushDownFilter PushDownFilter.cpp PushDownFilter.hpp)

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/590b6f01/query_optimizer/rules/FuseJoinSelect.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/FuseJoinSelect.cpp b/query_optimizer/rules/FuseJoinSelect.cpp
new file mode 100644
index 0000000..a776578
--- /dev/null
+++ b/query_optimizer/rules/FuseJoinSelect.cpp
@@ -0,0 +1,41 @@
+#include "query_optimizer/rules/FuseJoinSelect.hpp"
+
+#include "query_optimizer/physical/HashJoin.hpp"
+#include "query_optimizer/physical/PatternMatcher.hpp"
+#include "query_optimizer/physical/Selection.hpp"
+
+namespace quickstep {
+namespace optimizer {
+
+namespace P = ::quickstep::optimizer::physical;
+
+P::PhysicalPtr FuseJoinSelect::apply(const P::PhysicalPtr &input) {
+  DCHECK(input->getPhysicalType() == P::PhysicalType::kTopLevelPlan);
+
+  return applyInternal(input);
+}
+
+P::PhysicalPtr FuseJoinSelect::applyInternal(const P::PhysicalPtr &input) {
+  P::HashJoinPtr hash_join;
+  const bool is_hash_inner_join =
+      P::SomeHashJoin::MatchesWithConditionalCast(input, &hash_join)
+          && hash_join->join_type() == P::HashJoin::JoinType::kInnerJoin;
+
+  bool fuse_right = false;
+
+  if (is_hash_inner_join) {
+    //auto &left = hash_join->left();
+    auto &right = hash_join->right();
+    P::SelectionPtr selection;
+    const bool is_right_child_selection =
+        P::SomeSelection::MatchesWithConditionalCast(right, &selection);
+    if (is_right_child_selection) {
+      if (selection->input() != nullptr) {
+
+      }
+    }
+  }
+}
+
+}
+}

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/590b6f01/query_optimizer/rules/FuseJoinSelect.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/FuseJoinSelect.hpp b/query_optimizer/rules/FuseJoinSelect.hpp
new file mode 100644
index 0000000..d2ed5d8
--- /dev/null
+++ b/query_optimizer/rules/FuseJoinSelect.hpp
@@ -0,0 +1,26 @@
+#ifndef QUICKSTEP_QUERY_OPTIMIZER_RULES_FUSE_JOIN_SELECT_HPP_
+#define QUICKSTEP_QUERY_OPTIMIZER_RULES_FUSE_JOIN_SELECT_HPP_
+
+#include "query_optimizer/physical/Physical.hpp"
+#include "query_optimizer/rules/Rule.hpp"
+
+namespace quickstep {
+namespace optimizer {
+
+namespace P = ::quickstep::optimizer::physical;
+
+class FuseJoinSelect : public Rule<physical::Physical> {
+ public:
+  FuseJoinSelect() {
+  }
+
+  P::PhysicalPtr apply(const P::PhysicalPtr &input) override;
+
+ private:
+  P::PhysicalPtr applyInternal(const P::PhysicalPtr &input);
+};
+
+}
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/590b6f01/relational_operators/HashJoinOperator.cpp
----------------------------------------------------------------------
diff --git a/relational_operators/HashJoinOperator.cpp b/relational_operators/HashJoinOperator.cpp
index 667df1e..2dec2c5 100644
--- a/relational_operators/HashJoinOperator.cpp
+++ b/relational_operators/HashJoinOperator.cpp
@@ -84,7 +84,7 @@ class MapBasedJoinedTupleCollector {
     return &joined_tuples_;
   }
 
- private:
+ protected:
   // NOTE(chasseur): It would also be possible to represent joined tuples for a
   // particular pair of blocks as a TupleIdSequence/BitVector over the
   // cross-product of all tuples from both blocks, but simply using pairs of
@@ -93,6 +93,25 @@ class MapBasedJoinedTupleCollector {
   std::unordered_map<block_id, std::vector<std::pair<tuple_id, tuple_id>>>
joined_tuples_;
 };
 
+class MapBasedJoinedTupleCollectorWithPredicate
+    : public MapBasedJoinedTupleCollector {
+ public:
+  MapBasedJoinedTupleCollectorWithPredicate(const Predicate *predicate)
+      : filter_predicate_(predicate) {
+  }
+
+  template <typename ValueAccessorT>
+  inline void operator()(const ValueAccessorT &accessor,
+                         const TupleReference &tref) {
+    const tuple_id tid = accessor.getCurrentPosition();
+    if (filter_predicate_->matchesForSingleTuple(accessor, tid)) {
+      joined_tuples_[tref.block].emplace_back(tref.tuple, tid);
+    }
+  }
+ private:
+  const Predicate *filter_predicate_;
+};
+
 class SemiAntiJoinTupleCollector {
  public:
   explicit SemiAntiJoinTupleCollector(const TupleStorageSubBlock &tuple_store) {
@@ -203,7 +222,8 @@ bool HashJoinOperator::getAllNonOuterJoinWorkOrders(
                                      selection,
                                      hash_table,
                                      output_destination,
-                                     storage_manager),
+                                     storage_manager,
+                                     filter_predicate_),
               op_index_);
         }
         started_ = true;
@@ -223,7 +243,8 @@ bool HashJoinOperator::getAllNonOuterJoinWorkOrders(
                 selection,
                 hash_table,
                 output_destination,
-                storage_manager),
+                storage_manager,
+                filter_predicate_),
             op_index_);
         ++num_workorders_generated_;
       }  // end while
@@ -422,26 +443,32 @@ void HashInnerJoinWorkOrder::execute() {
   const TupleStorageSubBlock &probe_store = probe_block->getTupleStorageSubBlock();
 
   std::unique_ptr<ValueAccessor> probe_accessor(probe_store.createValueAccessor());
-  MapBasedJoinedTupleCollector collector;
+
+
+  std::unique_ptr<MapBasedJoinedTupleCollector> collector
+    = (filter_predicate_ == nullptr)
+    ? std::make_unique<MapBasedJoinedTupleCollector>()
+    : std::make_unique<MapBasedJoinedTupleCollectorWithPredicate>(filter_predicate_);
+
   if (join_key_attributes_.size() == 1) {
     hash_table_.getAllFromValueAccessor(
         probe_accessor.get(),
         join_key_attributes_.front(),
         any_join_key_attributes_nullable_,
-        &collector);
+        collector.get());
   } else {
     hash_table_.getAllFromValueAccessorCompositeKey(
         probe_accessor.get(),
         join_key_attributes_,
         any_join_key_attributes_nullable_,
-        &collector);
+        collector.get());
   }
 
   const relation_id build_relation_id = build_relation_.getID();
   const relation_id probe_relation_id = probe_relation_.getID();
 
   for (std::pair<const block_id, std::vector<std::pair<tuple_id, tuple_id>>>
-           &build_block_entry : *collector.getJoinedTuples()) {
+           &build_block_entry : *collector->getJoinedTuples()) {
     BlockReference build_block =
         storage_manager_->getBlock(build_block_entry.first, build_relation_);
     const TupleStorageSubBlock &build_store = build_block->getTupleStorageSubBlock();

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/590b6f01/relational_operators/HashJoinOperator.hpp
----------------------------------------------------------------------
diff --git a/relational_operators/HashJoinOperator.hpp b/relational_operators/HashJoinOperator.hpp
index 5d3d7da..d67e11c 100644
--- a/relational_operators/HashJoinOperator.hpp
+++ b/relational_operators/HashJoinOperator.hpp
@@ -129,7 +129,8 @@ class HashJoinOperator : public RelationalOperator {
       const QueryContext::predicate_id residual_predicate_index,
       const QueryContext::scalar_group_id selection_index,
       const std::vector<bool> *is_selection_on_build = nullptr,
-      const JoinType join_type = JoinType::kInnerJoin)
+      const JoinType join_type = JoinType::kInnerJoin,
+      const Predicate *filter_predicate = nullptr)
       : RelationalOperator(query_id),
         build_relation_(build_relation),
         probe_relation_(probe_relation),
@@ -145,6 +146,7 @@ class HashJoinOperator : public RelationalOperator {
                                    ? std::vector<bool>()
                                    : *is_selection_on_build),
         join_type_(join_type),
+        filter_predicate_(filter_predicate),
         probe_relation_block_ids_(probe_relation_is_stored
                                       ? probe_relation.getBlocksSnapshot()
                                       : std::vector<block_id>()),
@@ -235,6 +237,7 @@ class HashJoinOperator : public RelationalOperator {
   const QueryContext::scalar_group_id selection_index_;
   const std::vector<bool> is_selection_on_build_;
   const JoinType join_type_;
+  const Predicate *filter_predicate_;
 
   std::vector<block_id> probe_relation_block_ids_;
   std::size_t num_workorders_generated_;
@@ -283,7 +286,8 @@ class HashInnerJoinWorkOrder : public WorkOrder {
       const std::vector<std::unique_ptr<const Scalar>> &selection,
       const JoinHashTable &hash_table,
       InsertDestination *output_destination,
-      StorageManager *storage_manager)
+      StorageManager *storage_manager,
+      const Predicate *filter_predicate = nullptr)
       : WorkOrder(query_id),
         build_relation_(build_relation),
         probe_relation_(probe_relation),
@@ -294,7 +298,8 @@ class HashInnerJoinWorkOrder : public WorkOrder {
         selection_(selection),
         hash_table_(hash_table),
         output_destination_(DCHECK_NOTNULL(output_destination)),
-        storage_manager_(DCHECK_NOTNULL(storage_manager)) {}
+        storage_manager_(DCHECK_NOTNULL(storage_manager)),
+        filter_predicate_(filter_predicate) {}
 
   /**
    * @brief Constructor for the distributed version.
@@ -368,6 +373,8 @@ class HashInnerJoinWorkOrder : public WorkOrder {
   InsertDestination *output_destination_;
   StorageManager *storage_manager_;
 
+  const Predicate *filter_predicate_;
+
   DISALLOW_COPY_AND_ASSIGN(HashInnerJoinWorkOrder);
 };
 
@@ -411,7 +418,8 @@ class HashSemiJoinWorkOrder : public WorkOrder {
       const std::vector<std::unique_ptr<const Scalar>> &selection,
       const JoinHashTable &hash_table,
       InsertDestination *output_destination,
-      StorageManager *storage_manager)
+      StorageManager *storage_manager,
+      const Predicate *filter_predicate = nullptr)
       : WorkOrder(query_id),
         build_relation_(build_relation),
         probe_relation_(probe_relation),
@@ -422,7 +430,8 @@ class HashSemiJoinWorkOrder : public WorkOrder {
         selection_(selection),
         hash_table_(hash_table),
         output_destination_(DCHECK_NOTNULL(output_destination)),
-        storage_manager_(DCHECK_NOTNULL(storage_manager)) {}
+        storage_manager_(DCHECK_NOTNULL(storage_manager)),
+        filter_predicate_(filter_predicate) {}
 
   /**
    * @brief Constructor for the distributed version.
@@ -492,6 +501,8 @@ class HashSemiJoinWorkOrder : public WorkOrder {
   InsertDestination *output_destination_;
   StorageManager *storage_manager_;
 
+  const Predicate *filter_predicate_;
+
   DISALLOW_COPY_AND_ASSIGN(HashSemiJoinWorkOrder);
 };
 
@@ -535,7 +546,8 @@ class HashAntiJoinWorkOrder : public WorkOrder {
       const std::vector<std::unique_ptr<const Scalar>> &selection,
       const JoinHashTable &hash_table,
       InsertDestination *output_destination,
-      StorageManager *storage_manager)
+      StorageManager *storage_manager,
+      const Predicate *filter_predicate)
       : WorkOrder(query_id),
         build_relation_(build_relation),
         probe_relation_(probe_relation),
@@ -546,7 +558,8 @@ class HashAntiJoinWorkOrder : public WorkOrder {
         selection_(selection),
         hash_table_(hash_table),
         output_destination_(DCHECK_NOTNULL(output_destination)),
-        storage_manager_(DCHECK_NOTNULL(storage_manager)) {}
+        storage_manager_(DCHECK_NOTNULL(storage_manager)),
+        filter_predicate_(filter_predicate) {}
 
   /**
    * @brief Constructor for the distributed version.
@@ -622,6 +635,8 @@ class HashAntiJoinWorkOrder : public WorkOrder {
   InsertDestination *output_destination_;
   StorageManager *storage_manager_;
 
+  const Predicate *filter_predicate_;
+
   DISALLOW_COPY_AND_ASSIGN(HashAntiJoinWorkOrder);
 };
 


Mime
View raw message