Some fixups

This commit is contained in:
JackyWoo 2024-09-13 13:35:29 +08:00
parent 577e2ae386
commit e2a18f70ed
3 changed files with 20 additions and 15 deletions

View File

@ -487,7 +487,7 @@ ConditionSelectivityEstimator MergeTreeData::getConditionSelectivityEstimatorByP
}
PartitionPruner partition_pruner(storage_snapshot->metadata, filter_dag, local_context);
Statistics merged_stats;
Statistics statistics;
if (partition_pruner.isUseless())
{
@ -495,8 +495,8 @@ ConditionSelectivityEstimator MergeTreeData::getConditionSelectivityEstimatorByP
for (const auto & part : parts)
try
{
auto stats = part->loadStatistics();
merged_stats.merge(stats);
auto part_statistics = part->loadStatistics();
statistics.merge(part_statistics);
}
catch (...)
{
@ -510,8 +510,8 @@ ConditionSelectivityEstimator MergeTreeData::getConditionSelectivityEstimatorByP
{
if (!partition_pruner.canBePruned(*part))
{
auto stats = part->loadStatistics();
merged_stats.merge(stats);
auto part_statistics = part->loadStatistics();
statistics.merge(part_statistics);
}
}
catch (...)
@ -520,7 +520,7 @@ ConditionSelectivityEstimator MergeTreeData::getConditionSelectivityEstimatorByP
}
}
return ConditionSelectivityEstimator(merged_stats);
return ConditionSelectivityEstimator(statistics);
}
bool MergeTreeData::supportsFinal() const

View File

@ -59,6 +59,11 @@ ISingleStatistics::ISingleStatistics(const SingleStatisticsDescription & stat_)
{
}
String ISingleStatistics::getTypeName() const
{
return stat.getTypeName();
}
ColumnStatistics::ColumnStatistics(const ColumnStatisticsDescription & stats_desc_, const String & column_name_)
: stats_desc(stats_desc_), column_name(column_name_)
{

View File

@ -47,7 +47,7 @@ public:
virtual Float64 estimateEqual(const Field & val) const; /// cardinality of val in the column
virtual Float64 estimateLess(const Field & val) const; /// summarized cardinality of values < val in the column
String getTypeName() const { return stat.getTypeName(); }
String getTypeName() const;
protected:
SingleStatisticsDescription stat;
@ -87,20 +87,19 @@ class ColumnsDescription;
using ColumnStatisticsPtr = std::shared_ptr<ColumnStatistics>;
using ColumnsStatistics = std::vector<ColumnStatisticsPtr>;
/**
* Statistics represent the statistics for a part, table or node in query plan.
* It is a computable data structure which means:
* 1. it can accumulate statistics for a dedicated column of multiple parts.
* 2. it can support more calculations which is needed in estimating complex predicates like `a > 1 and a < 100 or a in (1, 3, 500).
* For example column 'a' has a minmax statistics with range [1, 100], after estimate 'a>50' the range is [51, 100].
*/
/// Statistics represent the statistics for a part, table or node in query plan.
/// It is a computable data structure which means:
/// 1. it can accumulate statistics for a dedicated column of multiple parts.
/// 2. it can support more calculations which is needed in estimating complex predicates like `a > 1 and a < 100 or a in (1, 3, 500).
/// For example column 'a' has a minmax statistics with range [1, 100], after estimate 'a>50' the range is [51, 100].
class Statistics
{
public:
explicit Statistics() : total_row_count(0) { }
explicit Statistics(Float64 total_row_count_) : total_row_count(total_row_count_) { }
explicit Statistics(Float64 total_row_count_, const std::unordered_map<String, ColumnStatisticsPtr> & column_stats_)
: total_row_count(total_row_count_), column_stats(column_stats_)
: total_row_count(total_row_count_)
, column_stats(column_stats_)
{
}
@ -112,6 +111,7 @@ public:
private:
Float64 total_row_count;
/// column_name -> column_statistics
std::unordered_map<String, ColumnStatisticsPtr> column_stats;
};