Skip to content

sql: small view descriptor clean-ups#17475

Closed
knz wants to merge 4 commits intocockroachdb:masterfrom
knz:20170807-view-deps-new
Closed

sql: small view descriptor clean-ups#17475
knz wants to merge 4 commits intocockroachdb:masterfrom
knz:20170807-view-deps-new

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Aug 7, 2017

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.

@knz knz requested review from a team August 7, 2017 12:25
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@knz knz force-pushed the 20170807-view-deps-new branch from 0448757 to e43b655 Compare August 7, 2017 13:03
@knz knz changed the title [WIP] sql: make view descriptor robust to changes to dependencies sql: small view descriptor clean-ups Aug 7, 2017
@knz knz force-pushed the 20170807-view-deps-new branch from e43b655 to 8e6bbee Compare August 7, 2017 16:04
@knz knz requested a review from jordanlewis August 7, 2017 16:04
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Aug 8, 2017

Note that even if we push the work to fix #10023/#10083 to 1.2, I think this PR should still make it to 1.1.

knz added 4 commits August 23, 2017 12:10
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.
@knz knz force-pushed the 20170807-view-deps-new branch from 8e6bbee to 7b21914 Compare August 23, 2017 12:12
@knz knz requested review from a team August 23, 2017 12:12
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Aug 25, 2017

All right, this is rebased and again gtg. PTAL

@knz knz closed this Sep 2, 2017
@knz knz deleted the 20170807-view-deps-new branch September 2, 2017 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants