/* Find a index using its oid from storage layer, * throw exception if not exists * */ index::Index *StorageManager::GetIndexWithOid(oid_t database_oid, oid_t table_oid, oid_t index_oid) const { // Lookup table from storage layer auto table = GetTableWithOid(database_oid, table_oid); // Throw exception if not exists // Lookup index from storage layer return table->GetIndexWithOid(index_oid) .get(); // Throw exception if not exists }
/* Find a table using its oid from storage layer, * throw exception if not exists * */ DataTable *StorageManager::GetTableWithOid( oid_t database_oid, oid_t table_oid) const { LOG_TRACE("Getting table with oid %d from database with oid %d", database_oid, table_oid); // Lookup DB from storage layer auto database = GetDatabaseWithOid(database_oid); // Throw exception if not exists // Lookup table from storage layer return database->GetTableWithOid(table_oid); // Throw exception if not exists }
bool TableFactory::DropDataTable(oid_t database_oid, oid_t table_oid) { auto storage_manager = storage::StorageManager::GetInstance(); try { DataTable *table = (DataTable *)storage_manager->GetTableWithOid( database_oid, table_oid); delete table; } catch (CatalogException &e) { return false; } return true; }
storage::DataTable *Manager::GetTableWithOid(const oid_t database_oid, const oid_t table_oid) const { // Lookup DB auto database = GetDatabaseWithOid(database_oid); // Lookup table if (database != nullptr) { auto table = database->GetTableWithOid(table_oid); return table; } return nullptr; }
index::Index *Manager::GetIndexWithOid(const oid_t database_oid, const oid_t table_oid, const oid_t index_oid) const { // Lookup table auto table = GetTableWithOid(database_oid, table_oid); // Lookup index if (table != nullptr) { auto index = table->GetIndexWithOid(index_oid); return index; } return nullptr; }
void Database::UpdateStatsWithOid(const oid_t table_oid) const { LOG_INFO("Update table(%lu)'s stats in Database(%lu)", table_oid, database_oid); auto table = GetTableWithOid(table_oid); bridge::Bridge::SetNumberOfTuples(table_oid, table->GetNumberOfTuples()); for (oid_t index_offset = 0; index_offset < table->GetIndexCount(); index_offset++) { auto index = table->GetIndex(index_offset); bridge::Bridge::SetNumberOfTuples(index->GetOid(), index->GetNumberOfTuples()); } }
// Get a string representation for debugging const std::string Database::GetInfo() const { std::ostringstream os; os << "=====================================================\n"; os << "DATABASE(" << GetOid() << ") : \n"; oid_t table_count = GetTableCount(); os << "Table Count : " << table_count << "\n"; oid_t table_itr = 0; for (auto table : tables) { if (table != nullptr) { os << "(" << ++table_itr << "/" << table_count << ") " << "Table Name(" << table->GetOid() << ") : " << table->GetName() << "\n" << *(table->GetSchema()) << std::endl; oid_t index_count = table->GetIndexCount(); if (index_count > 0) { os << "Index Count : " << index_count << std::endl; for (oid_t index_itr = 0; index_itr < index_count; index_itr++) { index::Index *index = table->GetIndex(index_itr); switch (index->GetIndexType()) { case INDEX_CONSTRAINT_TYPE_PRIMARY_KEY: os << "primary key index \n"; break; case INDEX_CONSTRAINT_TYPE_UNIQUE: os << "unique index \n"; break; default: os << "default index \n"; break; } os << *index << std::endl; } } if (table->HasForeignKeys()) { os << "foreign tables \n"; oid_t foreign_key_count = table->GetForeignKeyCount(); for (oid_t foreign_key_itr = 0; foreign_key_itr < foreign_key_count; foreign_key_itr++) { auto foreign_key = table->GetForeignKey(foreign_key_itr); auto sink_table_oid = foreign_key->GetSinkTableOid(); auto sink_table = GetTableWithOid(sink_table_oid); auto sink_table_schema = sink_table->GetSchema(); os << "table name : " << sink_table->GetName() << " " << *sink_table_schema << std::endl; } } } } os << "=====================================================\n"; return os.str(); }