Conversation
A view's defining query is resolved at CREATE time, and it may read another view or a materialized view. The dependency query only collected tables (relkind in r, p), so a view that reads a view carried no dependency and was emitted in an arbitrary order. The dependency now carries the relation's relkind, and the generators map it to the vertex that emits that relation's statement — a view is created under the table vertex id but dropped under its own, a materialized view under its own. The dependency query also now restricts to the object's own rewrite rule: `d.refobjid = c.oid` alone also matches the rules of every other view that reads this one, which reported those readers as dependencies of this object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
A view or materialized view is now ordered after the views and materialized views its defining query reads.
relkindinr,p,v,mand carries the kind in each dependency.TableDependencygainsKind, and the view and materialized-view generators map a dependency to the vertex that emits that relation's statement: a view is created under the table vertex id but dropped under its own, a materialized view under its own.d.refobjid = c.oidalone also matches the rules of every other view that reads this one, so those readers were reported as dependencies of this object; with only tables in the filter the extra rows were harmless, with views and materialized views they are not.Why
PostgreSQL resolves a view's defining query at
CREATE VIEWtime, and a view's query may read another view. Nothing ordered a view against the views it reads, so a plan that creates both could emit the reader first and fail:Known limitation
A view whose dependency view is dropped or recreated is not itself recreated by this change: the per-column recreation check only applies to tables, whose columns are modelled per column. That case already failed before this change (the dependency was not tracked at all), so nothing regresses, but the cascade is not implemented.
Validation
go test ./...New acceptance cases: a materialized view reading a view created in the same plan, and a view reading another view, each asserting the exact statement order.