-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Support arbitrary nesting in database and table names. #71171
Description
Use case
-
Allow to plug in external catalogs with databases and tables into a database in ClickHouse. This adds a level of nesting, as a database in ClickHouse can contain other databases.
-
Compatibility with Postgres, which has a two-level hierarchy with databases and schemas.
Describe the solution you'd like
We already allow database and table names with arbitrary characters, including dots. For example, if you have a database named a.b and a table named c.d with a column e.f, you can query it with SELECT "a.b"."c.d"."e.f" FROM "a.b"."c.d" - if you properly quoted these names.
The idea is to allow writing these names without quotes and resolve the ambiguity.
When a user writes SELECT a.b.c.d.e.f, we will check all combinations:
- if database
a.b.c.dexists with tableeand columnf; - if database
a.b.cexists with tabled.eand columnf; - if database
a.b.cexists with tabledand columne.f; - if database
a.bexists with tablec.d.eand columnf; - if database
a.bexists with tablec.dand columne.f; - if database
a.bexists with tablecand columnd.e.f; - if database
aexists with tableb.c.d.eand columnf; - if database
aexists with tableb.c.dand columne.f; - if database
aexists with tableb.cand columnd.e.f; - if database
aexists with tableband columnc.d.e.f; - if the current database has table
a.b.c.d.eand columnf; - if the current database has table
a.b.c.dand columne.f; - if the current database has table
a.b.cand columnd.e.f; - if the current database has table
a.band columnc.d.e.f; - if the current database has table
aand columnb.c.d.e.f; - if one of the tables in a query's FROM section has a column
a.b.c.d.e.f, which name is not ambiguous;
When a user does USE x we will allow it even if x is a prefix component of any database name - for example, if database x does not exist, but there are x.y and/or x.z, it is allowed to USE x.
When a user does USE x.y we will allow it even if y is a prefix of any table name.
For example, if database x.y does not exist, but there are tables x."y.a" and/or x."y.b", it is allowed to USE x.y.
Additionally, we can allow a relative USE statement when, assuming you are inside database a, the statement USE b could dive into a.b if it exists.
When a user does SHOW TABLES, we list tables under a certain prefix, possibly from different databases.
GRANT and REVOKE queries for prefixes are translated to corresponding wildcard grants.
Describe the alternative
A viable alternative is: don't do that.