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: Fixed the union-all elimiation bug regarding non-attribute project expression.
Date Wed, 09 May 2018 19:49:49 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/master 185c17ca8 -> 06982e9a6


Fixed the union-all elimiation bug regarding non-attribute project expression.


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

Branch: refs/heads/master
Commit: 06982e9a6375926244277e8cb8dc018ead87cdbe
Parents: 185c17c
Author: Zuyu Zhang <zuyu@cs.wisc.edu>
Authored: Mon May 7 23:58:35 2018 -0500
Committer: Zuyu Zhang <zuyu@cs.wisc.edu>
Committed: Tue May 8 11:04:22 2018 -0500

----------------------------------------------------------------------
 cli/tests/command_executor/Analyze.test      | 32 ++++++++++--
 query_optimizer/physical/Aggregate.cpp       | 17 -------
 query_optimizer/physical/Aggregate.hpp       |  3 --
 query_optimizer/physical/CMakeLists.txt      |  1 -
 query_optimizer/rules/EliminateEmptyNode.cpp | 61 +++++++++++------------
 5 files changed, 56 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06982e9a/cli/tests/command_executor/Analyze.test
----------------------------------------------------------------------
diff --git a/cli/tests/command_executor/Analyze.test b/cli/tests/command_executor/Analyze.test
index ff20d9e..c391848 100644
--- a/cli/tests/command_executor/Analyze.test
+++ b/cli/tests/command_executor/Analyze.test
@@ -36,6 +36,7 @@ SELECT COUNT(*) FROM r;
 +--------------------+
 ==
 
+# EliminateEmptyNode applies after having the exact stats.
 \analyze
 --
 Analyzing r ... done
@@ -43,6 +44,7 @@ Analyzing s ... done
 Analyzing t ... done
 ==
 
+# Aggregate on an empty table.
 SELECT COUNT(*) FROM r;
 --
 +--------------------+
@@ -52,6 +54,7 @@ SELECT COUNT(*) FROM r;
 +--------------------+
 ==
 
+# Aggregate on an empty table.
 SELECT MIN(src) FROM r;
 --
 +-----------+
@@ -61,6 +64,7 @@ SELECT MIN(src) FROM r;
 +-----------+
 ==
 
+# InsertSelection on an empty table.
 INSERT INTO r SELECT * FROM s;
 SELECT r.src, r.dst FROM r;
 DELETE FROM r;
@@ -73,6 +77,12 @@ DELETE FROM r;
 +-----------+-----------+
 ==
 
+# Compute the exact stats for r after updates.
+\analyze r
+--
+Analyzing r ... done
+==
+
 # One side of InnerJoin is empty.
 SELECT r.src, r.dst
 FROM r, t
@@ -136,9 +146,9 @@ SELECT t.src, t.dst FROM t;
 ==
 
 # Union on two InnerJoins, one of which involves an empty relation.
-SELECT r.src, r.dst FROM r, s WHERE r.src=s.src AND r.dst=s.dst
+SELECT r.src, s.dst FROM r, s WHERE r.src=s.src AND r.dst=s.dst
 UNION
-SELECT s.src, s.dst FROM s, t WHERE s.src=t.src AND s.dst=t.dst;
+SELECT s.src, t.dst FROM s, t WHERE s.src=t.src AND s.dst=t.dst;
 --
 +-----------+-----------+
 |src        |dst        |
@@ -148,9 +158,9 @@ SELECT s.src, s.dst FROM s, t WHERE s.src=t.src AND s.dst=t.dst;
 ==
 
 # Union All on two InnerJoins, one of which involves an empty relation.
-SELECT r.src, r.dst FROM r, s WHERE r.src=s.src AND r.dst=s.dst
+SELECT r.src, s.dst FROM r, s WHERE r.src=s.src AND r.dst=s.dst
 UNION ALL
-SELECT s.src, s.dst FROM s, t WHERE s.src=t.src AND s.dst=t.dst;
+SELECT s.src, t.dst FROM s, t WHERE s.src=t.src AND s.dst=t.dst;
 --
 +-----------+-----------+
 |src        |dst        |
@@ -160,6 +170,20 @@ SELECT s.src, s.dst FROM s, t WHERE s.src=t.src AND s.dst=t.dst;
 +-----------+-----------+
 ==
 
+# Union All on two InnerJoins, one of which involves an empty relation.
+# One of the project expressions is a ScalarLiteral.
+SELECT s.src, r.dst FROM r, s WHERE r.src=s.src AND r.dst=s.dst
+UNION ALL
+SELECT 1 AS src, s.dst FROM s, t WHERE s.src=t.src AND s.dst=t.dst;
+--
++-----------+-----------+
+|src        |dst        |
++-----------+-----------+
+|          1|          0|
+|          1|          0|
++-----------+-----------+
+==
+
 DROP TABLE r;
 DROP TABLE s;
 DROP TABLE t;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06982e9a/query_optimizer/physical/Aggregate.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/physical/Aggregate.cpp b/query_optimizer/physical/Aggregate.cpp
index 5ae9fc7..a8b86b6 100644
--- a/query_optimizer/physical/Aggregate.cpp
+++ b/query_optimizer/physical/Aggregate.cpp
@@ -27,7 +27,6 @@
 #include "query_optimizer/expressions/AttributeReference.hpp"
 #include "query_optimizer/expressions/ExpressionUtil.hpp"
 #include "query_optimizer/expressions/NamedExpression.hpp"
-#include "query_optimizer/expressions/PatternMatcher.hpp"
 #include "query_optimizer/expressions/Predicate.hpp"
 #include "query_optimizer/physical/PartitionSchemeHeader.hpp"
 #include "query_optimizer/physical/Physical.hpp"
@@ -93,22 +92,6 @@ std::vector<E::AttributeReferencePtr> Aggregate::getReferencedAttributes()
   return referenced_attributes;
 }
 
-PhysicalPtr Aggregate::copyWithNewProjectExpressions(
-    const std::vector<E::NamedExpressionPtr> &output_expressions) const {
-  DCHECK_EQ(aggregate_expressions_.size(), output_expressions.size());
-
-  std::vector<E::AliasPtr> new_aggregate_expressions;
-  new_aggregate_expressions.reserve(aggregate_expressions_.size());
-  for (const auto &output_expression : output_expressions) {
-    DCHECK(E::SomeAlias::Matches(output_expression));
-
-    new_aggregate_expressions.push_back(
-        std::static_pointer_cast<const E::Alias>(output_expression));
-  }
-
-  return Create(input_, grouping_expressions_, new_aggregate_expressions, filter_predicate_);
-}
-
 void Aggregate::getFieldStringItems(
     std::vector<std::string> *inline_field_names,
     std::vector<std::string> *inline_field_values,

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06982e9a/query_optimizer/physical/Aggregate.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/physical/Aggregate.hpp b/query_optimizer/physical/Aggregate.hpp
index 736082c..68f8811 100644
--- a/query_optimizer/physical/Aggregate.hpp
+++ b/query_optimizer/physical/Aggregate.hpp
@@ -103,9 +103,6 @@ class Aggregate : public Physical {
                   has_repartition, partition_scheme_header);
   }
 
-  PhysicalPtr copyWithNewProjectExpressions(
-      const std::vector<expressions::NamedExpressionPtr> &output_expressions) const
override;
-
   bool maybeCopyWithPrunedExpressions(
       const expressions::UnorderedNamedExpressionSet &referenced_expressions,
       PhysicalPtr *output) const override {

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06982e9a/query_optimizer/physical/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_optimizer/physical/CMakeLists.txt b/query_optimizer/physical/CMakeLists.txt
index 9f866b8..437488a 100644
--- a/query_optimizer/physical/CMakeLists.txt
+++ b/query_optimizer/physical/CMakeLists.txt
@@ -59,7 +59,6 @@ target_link_libraries(quickstep_queryoptimizer_physical_Aggregate
                       quickstep_queryoptimizer_expressions_AttributeReference
                       quickstep_queryoptimizer_expressions_ExpressionUtil
                       quickstep_queryoptimizer_expressions_NamedExpression
-                      quickstep_queryoptimizer_expressions_PatternMatcher
                       quickstep_queryoptimizer_expressions_Predicate
                       quickstep_queryoptimizer_physical_PartitionSchemeHeader
                       quickstep_queryoptimizer_physical_Physical

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/06982e9a/query_optimizer/rules/EliminateEmptyNode.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/rules/EliminateEmptyNode.cpp b/query_optimizer/rules/EliminateEmptyNode.cpp
index fd1c383..f619e67 100644
--- a/query_optimizer/rules/EliminateEmptyNode.cpp
+++ b/query_optimizer/rules/EliminateEmptyNode.cpp
@@ -153,42 +153,37 @@ P::PhysicalPtr ApplyToNode(const P::PhysicalPtr &node) {
 
 P::PhysicalPtr CopyWithNewProjectExpressions(const P::UnionAllPtr &union_all,
                                              const P::PhysicalPtr &child) {
-  const auto &project_attributes = union_all->project_attributes();
+  const std::vector<E::NamedExpressionPtr> *project_expressions = nullptr;
 
-  std::vector<E::NamedExpressionPtr> alias_expressions;
-  P::AggregatePtr aggregate;
-  if (P::SomeAggregate::MatchesWithConditionalCast(child, &aggregate)) {
-    const auto &aggregate_expressions = aggregate->aggregate_expressions();
-    alias_expressions.reserve(aggregate_expressions.size());
-
-    int aid = 0;
-    for (const auto &project_attribute : project_attributes) {
-      const auto alias_referenced_attributes =
-          aggregate_expressions[aid]->getReferencedAttributes();
-      DCHECK_EQ(1u, alias_referenced_attributes.size());
-
-      alias_expressions.emplace_back(E::Alias::Create(
-          project_attribute->id(),
-          alias_referenced_attributes.front(),
-          project_attribute->attribute_name(),
-          project_attribute->attribute_alias(),
-          project_attribute->relation_name()));
-      ++aid;
+  switch (child->getPhysicalType()) {
+    case P::PhysicalType::kHashJoin:
+    case P::PhysicalType::kNestedLoopsJoin: {
+      const auto &join = std::static_pointer_cast<const P::Join>(child);
+      project_expressions = &(join->project_expressions());
+      break;
     }
-  } else {
-    const auto child_output_attributes = child->getOutputAttributes();
-    alias_expressions.reserve(child_output_attributes.size());
-
-    int aid = 0;
-    for (const auto &project_attribute : project_attributes) {
-      alias_expressions.emplace_back(E::Alias::Create(
-          project_attribute->id(),
-          child_output_attributes[aid],
-          project_attribute->attribute_name(),
-          project_attribute->attribute_alias(),
-          project_attribute->relation_name()));
-      ++aid;
+    case P::PhysicalType::kSelection: {
+      const auto &selection = std::static_pointer_cast<const P::Selection>(child);
+      project_expressions = &(selection->project_expressions());
+      break;
     }
+    default:
+      LOG(FATAL) << "Unexpected PhysicalType.";
+  }
+  DCHECK(project_expressions);
+
+  std::vector<E::NamedExpressionPtr> alias_expressions;
+  alias_expressions.reserve(project_expressions->size());
+
+  int aid = 0;
+  for (const auto &project_attribute : union_all->project_attributes()) {
+    alias_expressions.emplace_back(E::Alias::Create(
+        project_attribute->id(),
+        (*project_expressions)[aid],
+        project_attribute->attribute_name(),
+        project_attribute->attribute_alias(),
+        project_attribute->relation_name()));
+    ++aid;
   }
 
   return child->copyWithNewProjectExpressions(alias_expressions);


Mime
View raw message