You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by zu...@apache.org on 2017/01/11 01:01:37 UTC

[45/50] incubator-quickstep git commit: Fixed PlanVisualizer crashes

Fixed PlanVisualizer crashes


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

Branch: refs/heads/quickstep_partition_parser_support
Commit: 1b0328bd29a38e259d89f5bcf8142b1f5aa1ba50
Parents: 6ae0cdd
Author: Jianqiao Zhu <ji...@cs.wisc.edu>
Authored: Wed Dec 14 18:41:38 2016 -0600
Committer: Jianqiao Zhu <ji...@cs.wisc.edu>
Committed: Wed Dec 14 20:48:21 2016 -0600

----------------------------------------------------------------------
 query_optimizer/cost_model/CostModel.hpp        | 28 ++++++++++++++++++++
 query_optimizer/cost_model/SimpleCostModel.cpp  |  3 ++-
 .../cost_model/StarSchemaSimpleCostModel.cpp    |  3 ++-
 utility/PlanVisualizer.cpp                      | 18 ++++++++++---
 4 files changed, 46 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/1b0328bd/query_optimizer/cost_model/CostModel.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/cost_model/CostModel.hpp b/query_optimizer/cost_model/CostModel.hpp
index 20bc208..21f1856 100644
--- a/query_optimizer/cost_model/CostModel.hpp
+++ b/query_optimizer/cost_model/CostModel.hpp
@@ -21,6 +21,8 @@
 #define QUERY_OPTIMIZER_COST_MODEL_COST_MODEL_HPP_
 
 #include <cstddef>
+#include <exception>
+#include <string>
 
 #include "query_optimizer/physical/Aggregate.hpp"
 #include "query_optimizer/physical/Physical.hpp"
@@ -35,6 +37,32 @@ namespace cost {
  */
 
 /**
+ * @brief Exception thrown for unsupported physical plan.
+ **/
+class UnsupportedPhysicalPlan : public std::exception {
+ public:
+  /**
+   * @brief Constructor.
+   *
+   * @param physical_plan The physical plan that is not supported by the cost
+   *        model.
+   **/
+  explicit UnsupportedPhysicalPlan(const physical::PhysicalPtr &physical_plan)
+      : message_("UnsupportedPhysicalPlan: \n" + physical_plan->toString()) {
+  }
+
+  ~UnsupportedPhysicalPlan() throw() {
+  }
+
+  virtual const char* what() const throw() {
+    return message_.c_str();
+  }
+
+ private:
+  std::string message_;
+};
+
+/**
  * @brief Interface to a cost model of physical plans.
  */
 class CostModel {

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/1b0328bd/query_optimizer/cost_model/SimpleCostModel.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/cost_model/SimpleCostModel.cpp b/query_optimizer/cost_model/SimpleCostModel.cpp
index a803c67..bf6da6a 100644
--- a/query_optimizer/cost_model/SimpleCostModel.cpp
+++ b/query_optimizer/cost_model/SimpleCostModel.cpp
@@ -24,6 +24,7 @@
 
 #include "catalog/CatalogRelation.hpp"
 #include "catalog/CatalogRelationStatistics.hpp"
+#include "query_optimizer/cost_model/CostModel.hpp"
 #include "query_optimizer/physical/Aggregate.hpp"
 #include "query_optimizer/physical/NestedLoopsJoin.hpp"
 #include "query_optimizer/physical/HashJoin.hpp"
@@ -82,7 +83,7 @@ std::size_t SimpleCostModel::estimateCardinality(
       return estimateCardinalityForWindowAggregate(
           std::static_pointer_cast<const P::WindowAggregate>(physical_plan));
     default:
-      LOG(FATAL) << "Unsupported physical plan:" << physical_plan->toString();
+      throw UnsupportedPhysicalPlan(physical_plan);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/1b0328bd/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp b/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
index 1075739..dfafa7d 100644
--- a/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
+++ b/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
@@ -25,6 +25,7 @@
 #include <vector>
 
 #include "catalog/CatalogRelation.hpp"
+#include "query_optimizer/cost_model/CostModel.hpp"
 #include "query_optimizer/expressions/AttributeReference.hpp"
 #include "query_optimizer/expressions/ComparisonExpression.hpp"
 #include "query_optimizer/expressions/ExprId.hpp"
@@ -93,7 +94,7 @@ std::size_t StarSchemaSimpleCostModel::estimateCardinality(
       return estimateCardinalityForWindowAggregate(
           std::static_pointer_cast<const P::WindowAggregate>(physical_plan));
     default:
-      LOG(FATAL) << "Unsupported physical plan:" << physical_plan->toString();
+      throw UnsupportedPhysicalPlan(physical_plan);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/1b0328bd/utility/PlanVisualizer.cpp
----------------------------------------------------------------------
diff --git a/utility/PlanVisualizer.cpp b/utility/PlanVisualizer.cpp
index 5d70c86..df7a20c 100644
--- a/utility/PlanVisualizer.cpp
+++ b/utility/PlanVisualizer.cpp
@@ -20,6 +20,7 @@
 #include "utility/PlanVisualizer.hpp"
 
 #include <cstddef>
+#include <exception>
 #include <memory>
 #include <set>
 #include <sstream>
@@ -189,10 +190,19 @@ void PlanVisualizer::visit(const P::PhysicalPtr &input) {
     }
   }
 
-  node_info.labels.emplace_back(
-      "est. # = " + std::to_string(cost_model_->estimateCardinality(input)));
-  node_info.labels.emplace_back(
-      "est. Selectivity = " + std::to_string(cost_model_->estimateSelectivity(input)));
+  try {
+    const std::size_t estimated_cardinality = cost_model_->estimateCardinality(input);
+    const double estimated_selectivity = cost_model_->estimateSelectivity(input);
+
+    node_info.labels.emplace_back(
+        "est. # = " + std::to_string(estimated_cardinality));
+    node_info.labels.emplace_back(
+        "est. Selectivity = " + std::to_string(estimated_selectivity));
+  } catch (const std::exception &e) {
+    // NOTE(jianqiao): CostModel::estimateCardinality() may throw UnsupportedPhysicalPlan
+    // exception for some type of physical nodes such as CreateTable.
+    // In this case, we omit the node's cardinality/selectivity information.
+  }
 }
 
 }  // namespace quickstep