@@ -257,41 +257,32 @@ std::shared_ptr<TableStats> StatsStorage::GetTableStats(
257
257
* AnalyzeStatsForAllTables - This function iterates all databases and
258
258
* datatables to collect their stats and store them in the column_stats_catalog.
259
259
*/
260
- // Deprecating this function because the notion is no longer true.
261
- // Needs to be handled differently. Used only in tests.
262
- ResultType StatsStorage::AnalyzeStatsForAllTables (
260
+ ResultType StatsStorage::AnalyzeStatsForAllTablesWithDatabaseOid (
261
+ oid_t database_oid,
263
262
UNUSED_ATTRIBUTE concurrency::TransactionContext *txn) {
264
263
if (txn == nullptr ) {
265
264
LOG_TRACE (" Do not have transaction to analyze all tables' stats." );
266
265
return ResultType::FAILURE;
267
266
}
268
267
269
268
auto storage_manager = storage::StorageManager::GetInstance ();
270
-
271
- oid_t database_count = storage_manager->GetDatabaseCount ();
272
- LOG_TRACE (" Database count: %u" , database_count);
273
- for (oid_t db_offset = 0 ; db_offset < database_count; db_offset++) {
274
- auto database = storage_manager->GetDatabaseWithOffset (db_offset);
275
- auto database_oid = database->GetOid ();
276
- if (database_oid == CATALOG_DATABASE_OID) {
269
+ auto database = storage_manager->GetDatabaseWithOid (database);
270
+ PELOTON_ASSERT (database != nullptr );
271
+ auto pg_database = catalog::Catalog::GetInstance ()
272
+ ->GetDatabaseObject (database_oid, txn);
273
+ auto table_objects = pg_database->GetTableObjects ();
274
+ for (auto &table_object_entry : table_objects) {
275
+ auto table_oid = table_object_entry.first ;
276
+ auto table_object = table_object_entry.second ;
277
+ if (table_object->GetSchemaName () == CATALOG_SCHEMA_NAME) {
277
278
continue ;
278
279
}
279
- auto pg_database = catalog::Catalog::GetInstance ()
280
- ->GetDatabaseObject (database_oid, txn);
281
- auto table_objects = pg_database->GetTableObjects ();
282
- for (auto &table_object_entry : table_objects) {
283
- auto table_oid = table_object_entry.first ;
284
- auto table_object = table_object_entry.second ;
285
- if (table_object->GetSchemaName () == CATALOG_SCHEMA_NAME) {
286
- continue ;
287
- }
288
- LOG_TRACE (" Analyzing table: %s" , table_object->GetTableName ().c_str ());
289
- auto table = database->GetTableWithOid (table_oid);
290
- std::unique_ptr<TableStatsCollector> table_stats_collector (
291
- new TableStatsCollector (table));
292
- table_stats_collector->CollectColumnStats ();
293
- InsertOrUpdateTableStats (table, table_stats_collector.get (), txn);
294
- }
280
+ LOG_TRACE (" Analyzing table: %s" , table_object->GetTableName ().c_str ());
281
+ auto table = database->GetTableWithOid (table_oid);
282
+ std::unique_ptr<TableStatsCollector> table_stats_collector (
283
+ new TableStatsCollector (table));
284
+ table_stats_collector->CollectColumnStats ();
285
+ InsertOrUpdateTableStats (table, table_stats_collector.get (), txn);
295
286
}
296
287
return ResultType::SUCCESS;
297
288
}
0 commit comments