quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jianq...@apache.org
Subject [6/7] incubator-quickstep git commit: Refine estimates for estimateCardinality for TableReference
Date Mon, 07 Nov 2016 21:44:11 GMT
Refine estimates for estimateCardinality for TableReference

- Use exact CatalogRelation statistics in SimpleCostModel's
  estimateCardinality method, whenever stats on that relation are available.


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

Branch: refs/heads/min-max-stats
Commit: c45d68e19c53ffb5a6e017aa62c7577860204d0b
Parents: 1340fcb
Author: Harshad Deshmukh <hbdeshmukh@apache.org>
Authored: Sat Nov 5 10:04:07 2016 -0500
Committer: Harshad Deshmukh <hbdeshmukh@apache.org>
Committed: Sun Nov 6 13:09:03 2016 -0600

----------------------------------------------------------------------
 query_optimizer/cost_model/CMakeLists.txt      | 1 +
 query_optimizer/cost_model/SimpleCostModel.cpp | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c45d68e1/query_optimizer/cost_model/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_optimizer/cost_model/CMakeLists.txt b/query_optimizer/cost_model/CMakeLists.txt
index d616696..032e34c 100644
--- a/query_optimizer/cost_model/CMakeLists.txt
+++ b/query_optimizer/cost_model/CMakeLists.txt
@@ -30,6 +30,7 @@ target_link_libraries(quickstep_queryoptimizer_costmodel_CostModel
 target_link_libraries(quickstep_queryoptimizer_costmodel_SimpleCostModel
                       glog
                       quickstep_catalog_CatalogRelation
+                      quickstep_catalog_CatalogRelationStatistics
                       quickstep_queryoptimizer_costmodel_CostModel
                       quickstep_queryoptimizer_physical_Aggregate
                       quickstep_queryoptimizer_physical_HashJoin

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c45d68e1/query_optimizer/cost_model/SimpleCostModel.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/cost_model/SimpleCostModel.cpp b/query_optimizer/cost_model/SimpleCostModel.cpp
index 74b62d6..a803c67 100644
--- a/query_optimizer/cost_model/SimpleCostModel.cpp
+++ b/query_optimizer/cost_model/SimpleCostModel.cpp
@@ -23,6 +23,7 @@
 #include <memory>
 
 #include "catalog/CatalogRelation.hpp"
+#include "catalog/CatalogRelationStatistics.hpp"
 #include "query_optimizer/physical/Aggregate.hpp"
 #include "query_optimizer/physical/NestedLoopsJoin.hpp"
 #include "query_optimizer/physical/HashJoin.hpp"
@@ -92,7 +93,13 @@ std::size_t SimpleCostModel::estimateCardinalityForTopLevelPlan(
 
 std::size_t SimpleCostModel::estimateCardinalityForTableReference(
     const P::TableReferencePtr &physical_plan) {
-  return physical_plan->relation()->estimateTupleCardinality();
+  const std::size_t num_tuples_in_relation =
+      physical_plan->relation()->getStatistics().getNumTuples();
+  if (num_tuples_in_relation == 0) {
+    return physical_plan->relation()->estimateTupleCardinality();
+  } else {
+    return num_tuples_in_relation;
+  }
 }
 
 std::size_t SimpleCostModel::estimateCardinalityForSelection(


Mime
View raw message