-
Notifications
You must be signed in to change notification settings - Fork 3.9k
sql: views do not track their dependencies properly #17269
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
Comments
After some brainstorm with @RaduBerinde and @jordanlewis there are multiple solutions. To compare them we need first to establish what the solution must solve:
Here are the solutions we found so far, I am giving them "small names" for the table below.
I had started as part of the work in #15388 to implement the solution "table-refs" however @jordanlewis is of the opinion we should invest the extra time into solution "track-named-columns" instead because it brings us closer to what pg does without making our logical planning / optimizations more complicated. |
From a strategic perspective:
Would this suggest we need to implement blunt-nochange or blunt-nodrop in the time being? |
|
(For reference: "What would postgres do?" - postgres has a plan-to-sql solution.) |
as a work around the user can drop the view and recreate.
The application will see errors until the new view is created. |
…dencies Prior to this patch, a view defined with ```sql CREATE VIEW vx AS SELECT k FROM (SELECT k, v FROM kv) ``` would only establish a dependency on column `k` of `kv`. Subsequently, `ALTER TABLE kv DROP COLUMN v` would be allowed without error and the view would become broken. There is a spectrum of solutions, see the discussion on cockroachdb#17269. This patch implements the simplest solution that still allows schema changes on depended-on tables: when a view is created, it now establishes a dependency on *all the columns that existed at the time the view is created*. New columns can be added without error; a subsequent patch can also address cockroachdb#10083 (renaming columns depended on by views) which is an orthogonal issue.
…dencies Prior to this patch, a view defined with ```sql CREATE VIEW vx AS SELECT k FROM (SELECT k, v FROM kv) ``` would only establish a dependency on column `k` of `kv`. Subsequently, `ALTER TABLE kv DROP COLUMN v` would be allowed without error and the view would become broken. There is a spectrum of solutions, see the discussion on cockroachdb#17269. This patch implements the simplest solution that still allows schema changes on depended-on tables: when a view is created, it now establishes a dependency on *all the columns that existed at the time the view is created*. New columns can be added without error; a subsequent patch can also address cockroachdb#10083 (renaming columns depended on by views) which is an orthogonal issue.
Moving to 1.2 since #17280 alleviates / works around the issue. |
Uh oh!
There was an error while loading. Please reload this page.
It is possible to break a view by removing a column from the table it depends on:
The problem is that the view tracks dependencies based on "needed columns", which is a result of logical plan optimization. A column that is named by the query but not used by the view results becomes "unneeded" and is thus not tracked as dependency. When it is deleted from the source table, the view plan cannot be constructed any more.
cc @cockroachdb/sql-planning @cockroachdb/sql-async
The text was updated successfully, but these errors were encountered: