Repository: incubator-quickstep Updated Branches: refs/heads/trace 26c04441c -> ba16c5aef (forced update)
Fix 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/ba16c5ae Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/ba16c5ae Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/ba16c5ae Branch: refs/heads/trace Commit: ba16c5aefa25f1d83e0e30e6a2a6a44c5eb984e0 Parents: 0bb163a Author: Jianqiao Zhu <jianq...@cs.wisc.edu> Authored: Mon Feb 12 22:01:56 2018 -0600 Committer: Jianqiao Zhu <jianq...@cs.wisc.edu> Committed: Mon Feb 12 22:55:34 2018 -0600 ---------------------------------------------------------------------- query_optimizer/rules/InjectJoinFilters.cpp | 47 ++++++++++++++++++------ query_optimizer/rules/InjectJoinFilters.hpp | 2 + 2 files changed, 38 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/ba16c5ae/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/ba16c5ae/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_;