Fix dependency ordering#285
Open
da77a wants to merge 1 commit into
Open
Conversation
db04607 to
cb97f29
Compare
Author
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.
Fix dependency ordering for functions, views
Functions and views can depend on each other in ways that pg_depend does
not fully track.
This commit fixes four classes of missing dependencies:
Function → table/view (composite type returns)
Functions using tables/views as composite return types (RETURNS view_name)
have pg_depend entries that were not being queried. Add a table_dependencies
subquery to GetProcs that finds these via pg_depend.
Function → table/view (body references)
plpgsql functions using %ROWTYPE, type[], or FROM/JOIN in their bodies
have no pg_depend entries (they are resolved at runtime).
So added simple parsing of pg_get_functiondef() output to find these.
View → view (dependency query bug)
The GetViews table_dependencies subquery had existing issues:
other views' rewrite rules, creating spurious cycles
View → function
Views calling functions in their definition (SELECT * FROM some_function()).
Add function_dependencies to GetViews via pg_depend and ordering in the view vertex generator.
Closes #248
Related: PR #268 (partial fix for case 1, abandoned due to cycles caused by case 3)
Testing
Validated against a substantial (~ 1000 object) schema containing views, functions, tables, triggers that exercises all four cases.
The reproducer from #248 (function with RETURNS view_type ordered before the view) is resolved.
Notes
HAS_UNTRACKABLE_DEPENDENCIEShazard is still emitted for plpgsql functions since text-based detection is best-effort.