-
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
sql: Support renaming objects depended on by views #10083
Comments
@knz Is this feasible in the 1.0 timeframe? It doesn't seem necessary, but I know you're working towards this. |
yes, this is feasible if we prioritize #12715 - that will give us a solution to this issue immediately. |
I got #13781 submitted as groundwork for this. |
Bringing into 1.0 milestone given the history of conversation, but if not necessary at this point, please move out into 1.1 milestone. Assigning @knz. Thanks! |
I can look into it. It is certainly easier now than it was three months ago, but I need to check relative to other work items. Unless we have a very strong need I would simply push it to 1.1 straight away. Our list of strong 1.0 issues is already large. |
@knz let's move out. |
Agreed - features should already be frozen and this isn't of critical major importance. |
@knz is this going to be resolved before 1.1 feature freeze? |
Iv'e scheduled a meeting to discuss this next week. |
It depends on #15388 too |
…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.
Reopening this, as we'd like to make progress on it before doing a larger migration to store ids instead of names in stored descriptors. |
I've been thinking about doing this without referring to ColumnIDs and it seems pretty tricky. With the way we store view queries right now, we could potentially have something like
Our resulting view would be Postgres avoids this by renaming one of the z's to z_1 but if this happens inside a subquery, we'd have to track which to rename as z_1. It would be tricky to do especially since we don't force subqueries to use aliases unlike Postgres' views. To support ids for #22212. If we want to update all views to use ids, we would have to perform a rename but we wouldn't have to deal with this variable capture issue. |
We’ve got a customer request on this too, specifically that a table rename should not require dropping a view dependent on that table. (Let me know if this is the right issue.) |
This is the right issue. We went through a bunch of discussions on this in the spring. The right want to do it will require machinery we don't currently have. See this long internal thread on the topic: https://cockroachlabs.slack.com/archives/C04U1BTF8/p1614712126092900. The crux of the problem is that scoping in SQL is complex. We have one component in the whole system which understands it: the |
relates to #83233 |
Experienced by a customer as part of a table restore process, see internal thread. |
In our initial implementation of views, we store a mostly-unmodified text form of the query. This prevents us from allowing renames on the objects used in the query without doing query rewriting, which is quite difficult.
We plan to switch to a semantic encoding that would only rely on the IDs of objects in the query when possible (initial discussion of such an encoding is in #10055). Once that time has come, we should remove the restrictions on renaming dependent objects.
Opening this primarily for tracking.
Jira issue: CRDB-6143
The text was updated successfully, but these errors were encountered: