Skip to content

sql: views do not track their dependencies properly #17269

@knz

Description

@knz

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

Metadata

Metadata

Assignees

Labels

A-schema-descriptorsRelating to SQL table/db descriptor handling.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions