quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jianq...@apache.org
Subject incubator-quickstep git commit: Minor revision to cost model
Date Mon, 07 Nov 2016 22:06:52 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/exact-filter 4510d5f9f -> 9d3ad752a


Minor revision to cost model


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

Branch: refs/heads/exact-filter
Commit: 9d3ad752a29aa44731ee65c617d8ac06439901b7
Parents: 4510d5f
Author: Jianqiao Zhu <jianqiao@cs.wisc.edu>
Authored: Mon Nov 7 16:06:46 2016 -0600
Committer: Jianqiao Zhu <jianqiao@cs.wisc.edu>
Committed: Mon Nov 7 16:06:46 2016 -0600

----------------------------------------------------------------------
 .../cost_model/StarSchemaSimpleCostModel.cpp    | 15 +++++--
 .../cost_model/StarSchemaSimpleCostModel.hpp    | 47 ++++++++++++++++++++
 2 files changed, 58 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9d3ad752/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp b/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
index c81fa96..986915c 100644
--- a/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
+++ b/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
@@ -143,9 +143,13 @@ std::size_t StarSchemaSimpleCostModel::estimateCardinalityForTableGenerator(
 
 std::size_t StarSchemaSimpleCostModel::estimateCardinalityForFilterInjection(
     const P::FilterInjectionPtr &physical_plan) {
+  double build_side_filter_selectivity =
+      estimateSelectivityForPredicate(physical_plan->build_side_filter_predicate(),
+                                      physical_plan->right());
   std::size_t left_cardinality = estimateCardinality(physical_plan->left());
   double right_selectivity = estimateSelectivity(physical_plan->right());
-  return static_cast<std::size_t>(left_cardinality * right_selectivity + 0.5);
+  return static_cast<std::size_t>(
+      left_cardinality * build_side_filter_selectivity * right_selectivity + 0.5);
 }
 
 std::size_t StarSchemaSimpleCostModel::estimateCardinalityForHashJoin(
@@ -283,8 +287,12 @@ double StarSchemaSimpleCostModel::estimateSelectivity(
     case P::PhysicalType::kFilterInjection: {
       const P::FilterInjectionPtr &filter_injection =
           std::static_pointer_cast<const P::FilterInjection>(physical_plan);
-      return estimateSelectivity(filter_injection->left()) *
-                 estimateSelectivity(filter_injection->right());
+      double left_selectivity = estimateSelectivity(filter_injection->left());
+      double right_selectivity = estimateSelectivity(filter_injection->right());
+      double build_side_filter_selectivity =
+          estimateSelectivityForPredicate(filter_injection->build_side_filter_predicate(),
+                                          filter_injection->right());
+      return left_selectivity * right_selectivity * build_side_filter_selectivity;
     }
     case P::PhysicalType::kHashJoin: {
       const P::HashJoinPtr &hash_join =
@@ -529,7 +537,6 @@ attribute_id StarSchemaSimpleCostModel::findCatalogRelationAttributeId(
   return kInvalidAttributeID;
 }
 
-
 }  // namespace cost
 }  // namespace optimizer
 }  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9d3ad752/query_optimizer/cost_model/StarSchemaSimpleCostModel.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/cost_model/StarSchemaSimpleCostModel.hpp b/query_optimizer/cost_model/StarSchemaSimpleCostModel.hpp
index 85914cd..b5def39 100644
--- a/query_optimizer/cost_model/StarSchemaSimpleCostModel.hpp
+++ b/query_optimizer/cost_model/StarSchemaSimpleCostModel.hpp
@@ -126,6 +126,13 @@ class StarSchemaSimpleCostModel : public CostModel {
         physical_plan, attribute->id(), StatType::kMax);
   }
 
+  template <typename CppType>
+  bool findMinMaxStatsCppValue(
+      const physical::PhysicalPtr &physical_plan,
+      const expressions::AttributeReferencePtr &attribute,
+      CppType *min_cpp_value,
+      CppType *max_cpp_value);
+
  private:
   std::size_t estimateCardinalityForAggregate(
       const physical::AggregatePtr &physical_plan);
@@ -185,6 +192,46 @@ class StarSchemaSimpleCostModel : public CostModel {
   DISALLOW_COPY_AND_ASSIGN(StarSchemaSimpleCostModel);
 };
 
+template <typename CppType>
+bool StarSchemaSimpleCostModel::findMinMaxStatsCppValue(
+    const physical::PhysicalPtr &physical_plan,
+    const expressions::AttributeReferencePtr &attribute,
+    CppType *min_cpp_value,
+    CppType *max_cpp_value) {
+  const TypedValue min_value =
+      findMinValueStat(physical_plan, attribute);
+  const TypedValue max_value =
+      findMaxValueStat(physical_plan, attribute);
+  if (min_value.isNull() || max_value.isNull()) {
+    return false;
+  }
+
+  switch (attribute->getValueType().getTypeID()) {
+    case TypeID::kInt: {
+      *min_cpp_value = min_value.getLiteral<int>();
+      *max_cpp_value = max_value.getLiteral<int>();
+      return true;
+    }
+    case TypeID::kLong: {
+      *min_cpp_value = min_value.getLiteral<std::int64_t>();
+      *max_cpp_value = max_value.getLiteral<std::int64_t>();
+      return true;
+    }
+    case TypeID::kFloat: {
+      *min_cpp_value = min_value.getLiteral<float>();
+      *max_cpp_value = max_value.getLiteral<float>();
+      return true;
+    }
+    case TypeID::kDouble: {
+      *min_cpp_value = min_value.getLiteral<double>();
+      *max_cpp_value = max_value.getLiteral<double>();
+      return true;
+    }
+    default:
+      return false;
+  }
+}
+
 /** @} */
 
 }  // namespace cost


Mime
View raw message