Skip to content

Commit 59a5860

Browse files
committed
also check if it's a system catalog
1 parent 217fa3f commit 59a5860

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/catalog/catalog.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,13 +954,14 @@ optional_ptr<SchemaCatalogEntry> Catalog::GetSchema(CatalogEntryRetriever &retri
954954
auto entries = GetCatalogEntries(retriever, catalog_name, schema_name);
955955
auto &context = retriever.GetContext();
956956
for (idx_t i = 0; i < entries.size(); i++) {
957-
if (!context.db->GetDatabaseManager().GetDatabase(context, entries[i].catalog)) {
958-
// check if the catalog is attached before we try to get the catalog
957+
auto entry_name = IsInvalidCatalog(entries[i].catalog) ? GetDefaultCatalog(retriever) : entries[i].catalog;
958+
// check whether the catalog is attached before trying to get it
959+
if (!context.db->GetDatabaseManager().GetDatabase(context, entry_name)) {
959960
continue;
960961
}
961962
auto on_not_found = i + 1 == entries.size() ? if_not_found : OnEntryNotFound::RETURN_NULL;
962963
auto &catalog = Catalog::GetCatalog(retriever, entries[i].catalog);
963-
auto result = catalog.GetSchema(retriever.GetContext(), schema_name, on_not_found, error_context);
964+
auto result = catalog.GetSchema(context, schema_name, on_not_found, error_context);
964965
if (result) {
965966
return result;
966967
}

src/catalog/catalog_search_path.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,17 @@ string CatalogSearchPath::GetDefaultCatalog(const string &schema) {
221221
}
222222

223223
vector<string> CatalogSearchPath::GetCatalogsForSchema(const string &schema) {
224-
vector<string> schemas;
224+
vector<string> catalogs;
225225
if (DefaultSchemaGenerator::IsDefaultSchema(schema)) {
226-
schemas.push_back(SYSTEM_CATALOG);
226+
catalogs.push_back(SYSTEM_CATALOG);
227227
} else {
228228
for (auto &path : paths) {
229229
if (StringUtil::CIEquals(path.schema, schema)) {
230-
schemas.push_back(path.catalog);
230+
catalogs.push_back(path.catalog);
231231
}
232232
}
233233
}
234-
return schemas;
234+
return catalogs;
235235
}
236236

237237
vector<string> CatalogSearchPath::GetSchemasForCatalog(const string &catalog) {

src/main/database_manager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ optional_ptr<AttachedDatabase> DatabaseManager::GetDatabase(ClientContext &conte
3232
if (StringUtil::Lower(name) == TEMP_CATALOG) {
3333
return context.client_data->temporary_objects.get();
3434
}
35+
if (StringUtil::Lower(name) == SYSTEM_CATALOG) {
36+
return system;
37+
}
3538
return reinterpret_cast<AttachedDatabase *>(databases->GetEntry(context, name).get());
3639
}
3740

0 commit comments

Comments
 (0)