Small adjust in star schema cost model for # distinct values
diff --git a/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp b/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
index 5aec4b4..6ab86e5 100644
--- a/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
+++ b/query_optimizer/cost_model/StarSchemaSimpleCostModel.cpp
@@ -493,7 +493,7 @@
return stat.getNumDistinctValues(rel_attr_id);
}
}
- return estimateCardinalityForTableReference(table_reference);
+ return estimateCardinalityForTableReference(table_reference) * 0.1;
}
bool StarSchemaSimpleCostModel::impliesUniqueAttributes(
@@ -527,7 +527,7 @@
std::static_pointer_cast<const P::TableReference>(physical_plan);
const CatalogRelationStatistics &stat =
table_reference->relation()->getStatistics();
- if (stat.hasNumTuples()) {
+ if (stat.isExact() && stat.hasNumTuples()) {
const std::size_t num_tuples = stat.getNumTuples();
for (const auto &attr : attributes) {
const attribute_id rel_attr_id =
diff --git a/query_optimizer/tests/execution_generator/Partition.test b/query_optimizer/tests/execution_generator/Partition.test
index 747b969..4b11a04 100644
--- a/query_optimizer/tests/execution_generator/Partition.test
+++ b/query_optimizer/tests/execution_generator/Partition.test
@@ -116,16 +116,16 @@
+-----------+--------------------+
|id |char_col |
+-----------+--------------------+
-| 2| 2 1.414214|
| 4| 4 2.000000|
-| 6| 6 2.449490|
| 8| 8 2.828427|
| 12| 12 3.464102|
-| 14| 14 3.741657|
| 16| 16 4.000000|
+| 24| 24 4.898979|
+| 2| 2 1.414214|
+| 6| 6 2.449490|
+| 14| 14 3.741657|
| 18| 18 4.242641|
| 22| 22 4.690416|
-| 24| 24 4.898979|
+-----------+--------------------+
==
@@ -193,15 +193,15 @@
+------------------------+--------------------+
|score |COUNT(*) |
+------------------------+--------------------+
+| 8| 1|
| 41.569219381653056| 1|
-| 76.367532368147124| 1|
| 64| 1|
| 52.38320341483518| 1|
-| 8| 1|
-| 2.8284271247461903| 1|
-| 14.696938456699067| 1|
+| 76.367532368147124| 1|
| 22.627416997969522| 1|
| 117.57550765359254| 1|
+| 2.8284271247461903| 1|
+| 14.696938456699067| 1|
| 103.18914671611546| 1|
+------------------------+--------------------+
==