Allow querying attached catalog from detached catalog #16289
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR allows users to execute queries that refer to attached catalogs from a detached default catalog. This is useful in multi-connection settings.
Say con1's default catalog, db1, is detached and db2 is still attached. Previously, querying a table in db2 from con1 would give a binder error:
To allow the above query, Binder::BindSchemaOrCatalog now uses Catalog::GetCatalogEntry instead of Catalog::GetCatalog to avoid immediately throwing binder exception when default catalog (db1) is not found. This allows the catalog/schema names of db2 to be set properly and go through the rest of binding phase.
Also, we want to throw a sensible error when con1 is referencing some non-existent table in db2. When an entry is not found, DuckDB calls CreateMissingEntryException, which creates default entries in the default catalog (db1). Previously, the error message looked like:
This PR immediately throws a catalog exception when an entry is missing and the default catalog is not attached, avoiding going on to create default entries. Now, it will throw "Catalog Error: Table with name non_existent_table does not exist!"