mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-28 02:21:59 +00:00
better trivial count optimization for storage Merge
This commit is contained in:
parent
bd17ee769e
commit
7ebb7d2955
@ -1295,38 +1295,35 @@ std::tuple<bool /* is_regexp */, ASTPtr> StorageMerge::evaluateDatabaseName(cons
|
||||
|
||||
bool StorageMerge::supportsTrivialCountOptimization() const
|
||||
{
|
||||
bool supported = true;
|
||||
forEachTable([&](const auto & table)
|
||||
{
|
||||
supported &= table->supportsTrivialCountOptimization();
|
||||
});
|
||||
return supported;
|
||||
return getFirstTable([&](const auto & table) { return !table->supportsTrivialCountOptimization(); }) == nullptr;
|
||||
}
|
||||
|
||||
std::optional<UInt64> StorageMerge::totalRows(const Settings & settings) const
|
||||
{
|
||||
UInt64 total_rows = 0;
|
||||
forEachTable([&](const auto & table)
|
||||
{
|
||||
std::optional<UInt64> rows = table->totalRows(settings);
|
||||
if (rows)
|
||||
total_rows += *rows;
|
||||
});
|
||||
return {total_rows};
|
||||
return totalRowsOrBytes([&](const auto & table) { return table->totalRows(settings); });
|
||||
}
|
||||
|
||||
std::optional<UInt64> StorageMerge::totalBytes(const Settings & settings) const
|
||||
{
|
||||
UInt64 total_bytes = 0;
|
||||
forEachTable([&](const auto & table)
|
||||
{
|
||||
std::optional<UInt64> bytes = table->totalBytes(settings);
|
||||
if (bytes)
|
||||
total_bytes += *bytes;
|
||||
});
|
||||
return {total_bytes};
|
||||
return totalRowsOrBytes([&](const auto & table) { return table->totalBytes(settings); });
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
std::optional<UInt64> StorageMerge::totalRowsOrBytes(F && func) const
|
||||
{
|
||||
UInt64 total_rows_or_bytes = 0;
|
||||
auto first_table = getFirstTable([&](const auto & table)
|
||||
{
|
||||
if (auto rows_or_bytes = func(table))
|
||||
{
|
||||
total_rows_or_bytes += *rows_or_bytes;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return first_table ? std::nullopt : std::make_optional(total_rows_or_bytes);
|
||||
}
|
||||
|
||||
void registerStorageMerge(StorageFactory & factory)
|
||||
{
|
||||
|
@ -79,8 +79,8 @@ public:
|
||||
|
||||
bool supportsTrivialCountOptimization() const override;
|
||||
|
||||
std::optional<UInt64> totalRows(const Settings &) const override;
|
||||
std::optional<UInt64> totalBytes(const Settings &) const override;
|
||||
std::optional<UInt64> totalRows(const Settings & settings) const override;
|
||||
std::optional<UInt64> totalBytes(const Settings & settings) const override;
|
||||
|
||||
private:
|
||||
std::optional<OptimizedRegularExpression> source_database_regexp;
|
||||
@ -118,6 +118,9 @@ private:
|
||||
|
||||
bool tableSupportsPrewhere() const;
|
||||
|
||||
template <typename F>
|
||||
std::optional<UInt64> totalRowsOrBytes(F && func) const;
|
||||
|
||||
friend class ReadFromMerge;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user