sql: small view descriptor clean-ups#17475
Closed
knz wants to merge 4 commits intocockroachdb:masterfrom
Closed
Conversation
Member
0448757 to
e43b655
Compare
e43b655 to
8e6bbee
Compare
Contributor
Author
If a view is defined by a query over table `d.t`, and this view's query is inspected (using either SHOW CREATE VIEW or pg_catalog) in the context of database `d`, ensure that the prefix `d.` is hidden. This is useful to ease reuse of the view definition when migrating databases.
This hidden bug cropped up while investigating different ways to encode view descriptors.
This patch makes it possible to use the numeric table reference syntax with a selection of columns (e.g. `[123(1,2,3)]`) when the reference is for a view. This selects a subset of the view's definition.
… the query Prior to this patch, a view defined with `CREATE VIEW v(x) FROM SELECT y FROM ...` would only store the name "x" in the descriptor. This would cause queries to pg_catalog or information_schema to hide the fact the view renders a column named "x" (only showing "SELECT y ..."). This patch improves upon this situation by forcing an explicit rename in the view query if the view definition changes the names. This was the most glaring limitation of the previous approach, but in addition to this a bug was lurking: a view created with `CREATE VIEW v(rowid) FROM TABLE t`, which *intends* to reveal the `rowid` such that subsequently `SELECT * FROM v` actually selects `rowid`, didn't work as intended: when the view plan was expanded, the `rowid` column would be picked from the underlying plan, which would make it hidden, which would subsequently cause `SELECT * FROM v` to not pick any column at all. The explicit rename approach taken in this patch fixes this bug. This bug probably never affected anyone given how unlikely the use case is, however fixing this fits the general effort of view descriptor improvements this patch is part of.
8e6bbee to
7b21914
Compare
Contributor
Author
|
All right, this is rebased and again gtg. PTAL |
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.
These are common functionality from #15388 which are of general interest, before I complete/refactor the remainder of the patch in #15388 into a different PR.