You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by ji...@apache.org on 2018/02/13 04:02:12 UTC

incubator-quickstep git commit: Fix to a bug in InjectJoinFilters

Repository: incubator-quickstep
Updated Branches:
  refs/heads/trace 0bb163a7e -> 26c04441c


Fix to a bug in InjectJoinFilters


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

Branch: refs/heads/trace
Commit: 26c04441c5ed1f54f2a5716312ee6e3cfc3982f3
Parents: 0bb163a
Author: Jianqiao Zhu <ji...@cs.wisc.edu>
Authored: Mon Feb 12 22:01:56 2018 -0600
Committer: Jianqiao Zhu <ji...@cs.wisc.edu>
Committed: Mon Feb 12 22:01:56 2018 -0600

----------------------------------------------------------------------
 query_optimizer/PhysicalGenerator.cpp       |  2 +-
 query_optimizer/rules/InjectJoinFilters.cpp | 42 +++++++++++++++++-------
 query_optimizer/rules/InjectJoinFilters.hpp |  2 ++
 3 files changed, 34 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/26c04441/query_optimizer/PhysicalGenerator.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/PhysicalGenerator.cpp b/query_optimizer/PhysicalGenerator.cpp
index 865cd11..b7b0db0 100644
--- a/query_optimizer/PhysicalGenerator.cpp
+++ b/query_optimizer/PhysicalGenerator.cpp
@@ -194,7 +194,7 @@ P::PhysicalPtr PhysicalGenerator::optimizePlan() {
              << physical_plan_->toString();
   }
 
-  DVLOG(4) << "Optimized physical plan:\n" << physical_plan_->toString();
+  std::cerr << "Optimized physical plan:\n" << physical_plan_->toString();
 
   if (FLAGS_visualize_plan) {
     quickstep::PlanVisualizer plan_visualizer;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/26c04441/query_optimizer/rules/InjectJoinFilters.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/InjectJoinFilters.cpp b/query_optimizer/rules/InjectJoinFilters.cpp
index 0aa2f5b..b85b8d8 100644
--- a/query_optimizer/rules/InjectJoinFilters.cpp
+++ b/query_optimizer/rules/InjectJoinFilters.cpp
@@ -62,17 +62,24 @@ 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. Wrap the top level plan 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 +153,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 +184,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 +439,23 @@ 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);
+
+  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/26c04441/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_;