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: Some fixes to cost model
Date Tue, 13 Feb 2018 22:21:52 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/transitive-closure 2aefd7bce -> f9e3d35a3


Some fixes 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/f9e3d35a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/f9e3d35a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/f9e3d35a

Branch: refs/heads/transitive-closure
Commit: f9e3d35a39ad2069d10c6cb604b5f81c71c9e5b1
Parents: 2aefd7b
Author: Jianqiao Zhu <jianqiao@cs.wisc.edu>
Authored: Tue Feb 13 16:21:34 2018 -0600
Committer: Jianqiao Zhu <jianqiao@cs.wisc.edu>
Committed: Tue Feb 13 16:21:34 2018 -0600

----------------------------------------------------------------------
 .../cost_model/StarSchemaSimpleCostModel.cpp    |  7 +--
 query_optimizer/rules/InjectJoinFilters.cpp     | 47 +++++++++++++++-----
 query_optimizer/rules/InjectJoinFilters.hpp     |  2 +
 3 files changed, 42 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/f9e3d35a/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp b/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
index 875c672..fe4c789 100644
--- a/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
+++ b/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
@@ -464,9 +464,10 @@ double StarSchemaSimpleCostModel::estimateSelectivityForPredicate(
            E::SomeScalarLiteral::Matches(comparison_expression->left()))) {
         for (const auto &child : physical_plan->children()) {
           if (E::ContainsExprId(child->getOutputAttributes(), attr->id())) {
-            const std::size_t child_num_distinct_values = estimateNumDistinctValues(attr->id(),
child);
+            const std::size_t child_num_distinct_values =
+                estimateNumDistinctValues(attr->id(), child);
             if (comparison_expression->isEqualityComparisonPredicate()) {
-              return 1.0 / child_num_distinct_values;
+              return 1.0 / std::max(child_num_distinct_values, static_cast<std::size_t>(1));
             } else {
               return 1.0 / std::max(std::min(child_num_distinct_values / 100.0, 10.0), 2.0);
             }
@@ -512,7 +513,7 @@ std::size_t StarSchemaSimpleCostModel::getNumDistinctValues(
       return stat.getNumDistinctValues(rel_attr_id);
     }
   }
-  return estimateCardinalityForTableReference(table_reference) * 0.5;
+  return estimateCardinalityForTableReference(table_reference) * 0.1;
 }
 
 bool StarSchemaSimpleCostModel::impliesUniqueAttributes(

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/f9e3d35a/query_optimizer/rules/InjectJoinFilters.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/InjectJoinFilters.cpp b/query_optimizer/rules/InjectJoinFilters.cpp
index 0aa2f5b..a92e433 100644
--- a/query_optimizer/rules/InjectJoinFilters.cpp
+++ b/query_optimizer/rules/InjectJoinFilters.cpp
@@ -62,17 +62,25 @@ P::PhysicalPtr InjectJoinFilters::apply(const P::PhysicalPtr &input)
{
   // Step 1. Transform applicable HashJoin nodes to FilterJoin nodes.
   P::PhysicalPtr output = transformHashJoinToFilters(input);
 
-  // Step 2. Push down FilterJoin nodes to be evaluated early.
+  if (output == input) {
+    return input;
+  }
+
+  // Step 2. If the top level plan is a filter join, wrap it with a Selection
+  // to stabilize output columns.
+  output = wrapSelection(output);
+
+  // Step 3. Push down FilterJoin nodes to be evaluated early.
   output = pushDownFilters(output);
 
-  // Step 3. Add Selection nodes for attaching the LIPFilters, if necessary.
+  // Step 4. Add Selection nodes for attaching the LIPFilters, if necessary.
   output = addFilterAnchors(output, false);
 
-  // Step 4. Because of the pushdown of FilterJoin nodes, there are optimization
+  // Step 5. Because of the pushdown of FilterJoin nodes, there are optimization
   // opportunities for projecting columns early.
   output = PruneColumns().apply(output);
 
-  // Step 5. For each FilterJoin node, attach its corresponding LIPFilter to
+  // Step 6. For each FilterJoin node, attach its corresponding LIPFilter to
   // proper nodes.
   concretizeAsLIPFilters(output, nullptr);
 
@@ -146,13 +154,8 @@ bool InjectJoinFilters::isTransformable(
 P::PhysicalPtr InjectJoinFilters::transformHashJoinToFilters(
     const P::PhysicalPtr &input) const {
   std::vector<P::PhysicalPtr> new_children;
-  bool has_changed_children = false;
   for (const P::PhysicalPtr &child : input->children()) {
-    const P::PhysicalPtr new_child = transformHashJoinToFilters(child);
-    if (child != new_child && !has_changed_children) {
-      has_changed_children = true;
-    }
-    new_children.push_back(new_child);
+    new_children.emplace_back(transformHashJoinToFilters(child));
   }
 
   P::HashJoinPtr hash_join;
@@ -182,7 +185,7 @@ P::PhysicalPtr InjectJoinFilters::transformHashJoinToFilters(
                                  hash_join->cloneOutputPartitionSchemeHeader());
   }
 
-  if (has_changed_children) {
+  if (input->children() != new_children) {
     return input->copyWithNewChildren(new_children);
   } else {
     return input;
@@ -437,5 +440,27 @@ bool InjectJoinFilters::findExactMinMaxValuesForAttributeHelper(
   }
 }
 
+P::PhysicalPtr InjectJoinFilters::wrapSelection(
+    const P::PhysicalPtr &input) const {
+  DCHECK(input->getPhysicalType() == P::PhysicalType::kTopLevelPlan);
+  const P::TopLevelPlanPtr top_level_plan =
+      std::static_pointer_cast<const P::TopLevelPlan>(input);
+
+  if (top_level_plan->plan()->getPhysicalType() != P::PhysicalType::kFilterJoin) {
+    return input;
+  }
+
+  const P::SelectionPtr selection =
+      P::Selection::Create(
+          top_level_plan->plan(),
+          E::ToNamedExpressions(top_level_plan->plan()->getOutputAttributes()),
+          nullptr /* filter_predicate */);
+
+  return P::TopLevelPlan::Create(selection,
+                                 top_level_plan->shared_subplans(),
+                                 top_level_plan->uncorrelated_subquery_map());
+}
+
+
 }  // namespace optimizer
 }  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/f9e3d35a/query_optimizer/rules/InjectJoinFilters.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/InjectJoinFilters.hpp b/query_optimizer/rules/InjectJoinFilters.hpp
index c5250b3..71a6c99 100644
--- a/query_optimizer/rules/InjectJoinFilters.hpp
+++ b/query_optimizer/rules/InjectJoinFilters.hpp
@@ -98,6 +98,8 @@ class InjectJoinFilters : public Rule<physical::Physical> {
       std::int64_t *min_cpp_value,
       std::int64_t *max_cpp_value) const;
 
+  physical::PhysicalPtr wrapSelection(const physical::PhysicalPtr &input) const;
+
   std::unique_ptr<cost::StarSchemaSimpleCostModel> cost_model_;
   std::unique_ptr<physical::LIPFilterConfiguration> lip_filter_configuration_;
 


Mime
View raw message