sql: fix the handling of current_schema and search_path#24718
Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom Apr 13, 2018
Merged
sql: fix the handling of current_schema and search_path#24718craig[bot] merged 1 commit intocockroachdb:masterfrom
craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
Member
6fe4d35 to
0b48e95
Compare
justinj
approved these changes
Apr 12, 2018
Contributor
justinj
left a comment
There was a problem hiding this comment.
there's also a search_path_test.go, not sure if there's an appropriate way to add this to that, but it does exist. either way LGTM
pkg/sql/sem/builtins/builtins.go
Outdated
|
|
||
| // Metadata functions. | ||
|
|
||
| // https://www.postgresql.org/docs/9.6/static/functions-info.html |
Contributor
There was a problem hiding this comment.
nit: maybe better to reference the most recent docs?
pkg/sql/sem/builtins/builtins.go
Outdated
| }, | ||
| }, | ||
|
|
||
| // https://www.postgresql.org/docs/9.6/static/functions-info.html |
pkg/sql/sem/builtins/builtins.go
Outdated
| }, | ||
| }, | ||
|
|
||
| // https://www.postgresql.org/docs/9.6/static/functions-info.html |
pkg/sql/sem/builtins/builtins.go
Outdated
| // For now, schemas are the same as databases. So, current_schemas | ||
| // returns the current database (if one has been set by the user) | ||
| // and the session's database search path. | ||
| // https://www.postgresql.org/docs/9.6/static/functions-info.html |
pkg/sql/sem/builtins/builtins.go
Outdated
| }, | ||
| }, | ||
|
|
||
| // https://www.postgresql.org/docs/9.6/static/functions-info.html |
Prior to this patch, CockroachDB was following the pg docs to the letter regarding the relationship between `search_path` and the "current schema": the current schema was taken to always be the first item in `search_path`, as indicated in https://www.postgresql.org/docs/10/static/functions-info.html ("current_schema returns the name of the schema that is first in the search path (or a null value if the search path is empty).") This in turn impacts the creation of objects (tables, views, etc) when the name is unqualified: pg also specifies that such objects are to be created in the current schema. Unfortunately the pg doc is incorrect, as pg has a more nuanced behavior: only the _valid_ schemas in `search_path` are considered to determine the current schema in that way. This was causing an unfortunate visible compatibility bug: if the user specified an invalid schema in the search path, subsequent create operations would fail with CockroachDB and succeed with pg. This patch corrects this issue by adopting pg's behavior. Ditto for `current_schemas`. Release note (sql change, bug fix): the built-in functions `current_schema` and `current_schemas` now only consider valid schemas, like PostgreSQL does.
0b48e95 to
ea95d9d
Compare
Contributor
Author
|
The search_path_test.go is at a lower level than this patch (and does not have access to a lookup context that can check the validity of schemas), so that doesn't seem the right place. |
Contributor
Author
|
bors r+ |
Contributor
Build failed (retrying...) |
craig bot
pushed a commit
that referenced
this pull request
Apr 12, 2018
24718: sql: fix the handling of current_schema and search_path r=knz a=knz Fixes #24472. Prior to this patch, CockroachDB was following the pg docs to the letter regarding the relationship between `search_path` and the "current schema": the current schema was taken to always be the first item in `search_path`, as indicated in https://www.postgresql.org/docs/9.6/static/functions-info.html ("current_schema returns the name of the schema that is first in the search path (or a null value if the search path is empty).") This in turn impacts the creation of objects (tables, views, etc) when the name is unqualified: pg also specifies that such objects are to be created in the current schema. Unfortunately the pg doc is incorrect, as pg has a more nuanced behavior: only the _valid_ schemas in `search_path` are considered to determine the current schema in that way. This was causing an unfortunate visible compatibility bug: if the user specified an invalid schema in the search path, subsequent create operations would fail with CockroachDB and succeed with pg. This patch corrects this issue by adopting pg's behavior. Ditto for `current_schemas`. Release note (sql change, bug fix): the built-in functions `current_schema` and `current_schemas` now only consider valid schemas, like PostgreSQL does. Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
Contributor
Build succeeded |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #24472.
Prior to this patch, CockroachDB was following the pg docs to the
letter regarding the relationship between
search_pathand the"current schema": the current schema was taken to always be the first
item in
search_path, as indicated inhttps://www.postgresql.org/docs/9.6/static/functions-info.html
("current_schema returns the name of the schema that is first in the
search path (or a null value if the search path is empty).")
This in turn impacts the creation of objects (tables, views, etc) when
the name is unqualified: pg also specifies that such objects are to be
created in the current schema.
Unfortunately the pg doc is incorrect, as pg has a more nuanced
behavior: only the valid schemas in
search_pathare considered todetermine the current schema in that way.
This was causing an unfortunate visible compatibility bug: if the user
specified an invalid schema in the search path, subsequent create
operations would fail with CockroachDB and succeed with pg.
This patch corrects this issue by adopting pg's behavior.
Ditto for
current_schemas.Release note (sql change, bug fix): the built-in functions
current_schemaandcurrent_schemasnow only consider validschemas, like PostgreSQL does.