-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cherry-pick 2.0: schema-related fixes #23041
Conversation
Release note (sql change): the special identifier `current_catalog` is supported as alias for `current_database()` for better compatibility with PostgreSQL.
Release note (sql change): `current_role` is recognized as an alias for `current_user` for better compatibility with PostgreSQL.
…standard At least one client app (Zippix) uses `SET SCHEMA`, defined by the SQL standard. `SET SCHEMA` is used by an app after discovering the available schemas in the `information_schema` tables. Postgres implements `SET SCHEMA` as an alias for `SET search_path =`, since the "current schema" in pg's dialect is defined exactly as "the first item in `search_path`". This patch makes CockroachDB do the same as pg. Release note (sql change): CockroachDB now recognizes the special syntax `SET SCHEMA <name>` as an alias for `SET search_path = <name>` for better compatibility with PostgreSQL.
Now that SHOW TABLES only shows tables in the public schema by default, and SET DATABASE only supports real databases and not (virtual) schemas, there is no simple way for a user to realize that there are multiple schemas in the first place, and which virtual schemas exist / are recognized. Release note (sql change): the new statement `SHOW SCHEMAS` reveals which are the valid virtual schemas next to the physical schema `public`.
With the introduction of compatibility with schema specifications, SHOW TABLES was modified to recognize the following two forms: SHOW TABLES FROM <db> SHOW TABLES FROM <db> . <schema> So one could, for example, issue `SHOW TABLES FROM system.pg_catalog` to see all tables in `system`'s `pg_catalog`. However this change broke a use case, as users were previously able to use `SHOW TABLES` directly on virtual schemas, e.g. `SHOW TABLES FROM crdb_internal`. This patch restores this functionality, by making `SHOW TABLES` resolve its parameter as if it was a star prefix in GRANT. That is, `SHOW TABLES FROM crdb_internal` will first try to find a database called `crdb_internal`, and if that fails will try the current database's schema called `crdb_internal`. Release note (bug fix): `SHOW TABLES` is now again able to inspect virtual schemas.
Requested/suggested by @rytaft: "pattern" is a bit of a technical word and is not necessary to convey the right meaning in the error message. Release note: None
cc @cockroachdb/release |
Prior to this patch, an attempt to populate one of the virtual schemas with a DDL statement would fail with the error "unsupported schema specification". This is not extremely clear, also incorrect on its face, since the virtual schemas are actually supported. This patch clarifies the error by reporting "schema cannot be modified" more explicitly. Suggested/requested by @rytaft. Release note (sql change): attempts to modify virtual schemas with DDL statements now fail with a clearer error message.
Reviewed 9 of 12 files at r4, 8 of 13 files at r5, 5 of 5 files at r6, 4 of 4 files at r7. pkg/sql/parser/sql.y, line 2874 at r7 (raw file):
[nit] remove tab character pkg/sql/sem/tree/show.go, line 165 at r7 (raw file):
pkg/sql/sem/tree/table_pattern.go, line 67 at r7 (raw file):
Might be good to move this line and the following Comments from Reviewable |
Becca I'll follow up on your requests in #23072. This PR here is merely a cherry-pick, I can't make changes here without first issuing a PR against master. |
Picks #22828.
Picks #22997.
Picks #22998.
Picks #22994.
Picks #23040.
Picks #23044.