-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: views do not track their dependencies properly #17269
Copy link
Copy link
Closed
Labels
A-schema-descriptorsRelating to SQL table/db descriptor handling.Relating to SQL table/db descriptor handling.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Milestone
Description
It is possible to break a view by removing a column from the table it depends on:
CREATE TABLE kv(k INT, v INT);
CREATE VIEW v1 AS SELECT k FROM (SELECT k,v FROM kv) AS t;
ALTER TABLE kv DROP COLUMN v;
SELECT * FROM v1; -- fails with `pq: column 2 does not exist`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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-schema-descriptorsRelating to SQL table/db descriptor handling.Relating to SQL table/db descriptor handling.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.