reafactor function

This commit is contained in:
skyoct 2023-12-15 04:49:38 +00:00
parent 0e91ee4642
commit 3319934055

View File

@ -1156,57 +1156,38 @@ std::tuple<bool /* is_regexp */, ASTPtr> StorageMerge::evaluateDatabaseName(cons
bool StorageMerge::supportsTrivialCountOptimization() const
{
bool is_support = true;
auto database_table_iterators = getDatabaseIterators(getContext());
for (auto & iterator : database_table_iterators)
forEachTable([&](const StoragePtr & table)
{
while (iterator->isValid())
{
const auto & table = iterator->table();
is_support = table->supportsTrivialCountOptimization();
iterator->next();
}
}
is_support &= table->supportsTrivialCountOptimization();
});
return is_support;
}
std::optional<UInt64> StorageMerge::totalRows(const Settings &) const
{
UInt64 total_rows = 0;
auto database_table_iterators = getDatabaseIterators(getContext());
for (auto & iterator : database_table_iterators)
forEachTable([&](const StoragePtr & table)
{
while (iterator->isValid())
auto table_rows = table->totalRows(getContext()->getSettingsRef());
if (table_rows)
{
const auto & table = iterator->table();
auto table_rows = table->totalRows(getContext()->getSettingsRef());
if (table_rows)
{
total_rows += *table_rows;
}
iterator->next();
total_rows += *table_rows;
}
}
});
return std::make_optional<UInt64>(total_rows);
}
std::optional<UInt64> StorageMerge::totalBytes(const Settings &) const
{
UInt64 total_bytes = 0;
auto database_table_iterators = getDatabaseIterators(getContext());
for (auto & iterator : database_table_iterators)
forEachTable([&](const StoragePtr & table)
{
while (iterator->isValid())
auto table_bytes = table->totalBytes(getContext()->getSettingsRef());
if (table_bytes)
{
const auto & table = iterator->table();
auto table_bytes = table->totalBytes(getContext()->getSettingsRef());
if (total_bytes)
{
total_bytes += *table_bytes;
}
iterator->next();
total_bytes += *table_bytes;
}
}
});
return std::make_optional<UInt64>(total_bytes);
}