fix some tests

This commit is contained in:
Han Fei 2023-09-12 18:30:55 +02:00
parent 57b5f3ca78
commit 430a4fda9c
2 changed files with 14 additions and 3 deletions

View File

@ -274,7 +274,8 @@ void MergeTreeWhereOptimizer::analyzeImpl(Conditions & res, const RPNBuilderTree
cond.selectivity = estimator.estimateSelectivity(node);
LOG_DEBUG(log, "Condition {} has selectivity {}", node.getASTNode()->dumpTree(), cond.selectivity);
if (node.getASTNode() != nullptr)
LOG_DEBUG(log, "Condition {} has selectivity {}", node.getASTNode()->dumpTree(), cond.selectivity);
}
if (where_optimizer_context.move_primary_key_columns_to_end_of_prewhere)

View File

@ -104,11 +104,19 @@ Float64 ConditionEstimator::estimateSelectivity(const RPNBuilderTreeNode & node)
return default_unknown_cond_factor;
}
auto it = column_estimators.find(col.value());
/// If there the estimator of the column is not found or there are no data at all,
/// we use dummy estimation.
bool dummy = total_count == 0;
ColumnEstimator estimator;
if (it != column_estimators.end())
{
estimator = it->second;
}
else
{
dummy = true;
}
auto [op, val] = extractBinaryOp(node, col.value());
if (op == "equals")
{
@ -119,10 +127,14 @@ Float64 ConditionEstimator::estimateSelectivity(const RPNBuilderTreeNode & node)
}
else if (op == "less" || op == "lessThan")
{
if (dummy)
return default_normal_cond_factor;
return estimator.estimateLess(val) / total_count;
}
else if (op == "greater" || op == "greaterThan")
{
if (dummy)
return default_normal_cond_factor;
return estimator.estimateGreater(val) / total_count;
}
else
@ -144,8 +156,6 @@ void MergeTreeStatisticFactory::registerCreator(StatisticType stat_type, Creator
MergeTreeStatisticFactory::MergeTreeStatisticFactory()
{
registerCreator(TDigest, TDigestCreator);
///registerCreator("cm_sketch", CMSketchCreator);
}
MergeTreeStatisticFactory & MergeTreeStatisticFactory::instance()