Repository navigation
fix(catalog): skip orphaned catalog rows when loading the snapshot - #847
Merged
Merged
Conversation
The functions, types and triggers queries left-joined pg_namespace (and pg_language, pg_proc, pg_class) while forcing those columns non-null with sqlx "!" overrides. A row whose referenced object no longer exists then produced a null that failed to decode, and since Snapshot::load uses try_join! the whole snapshot was discarded. pg_policies left-joins the namespace too, so policies on orphaned tables had the same problem. Inner-join the referenced objects and filter null policy schemas so orphaned rows are skipped, matching the queries that already inner-join. Fixes #842
The functions query had no order by, so its row order depended on the query plan. Switching to inner joins changed the plan and reordered the overloads hover lists, breaking the builtin_max snapshot. Order by oid so the result is deterministic.
Contributor
|
@psteinroe Oh I see, you already fixed ordering ok :). |
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.
A catalog row that references an object that no longer exists (e.g. a
pg_procrow whosepg_namespacerow is gone) made the whole snapshot fail to load, disabling every database-backed feature. Such rows are now skipped.Root cause
The
functions,typesandtriggersqueries left-joinedpg_namespace(andpg_language,pg_proc,pg_class) while forcing the joined columns non-null with sqlx!overrides. An orphaned row produced a null that failed to decode (ColumnDecode { source: UnexpectedNullError }), and becauseSnapshot::loadusestry_join!, that single row discarded the entire snapshot.policiesreadspg_policies, which itself left-joins the namespace, so policies on an orphaned table had the same problem.Fix
Those joins are now inner joins, and policies with a null schema are filtered out, matching the queries that already inner-join (
tables,columns,indexes,sequences,operators). I audited the remaining queries:extensionskeeps its left joins on purpose, and itsschemais already nullable.casts,roles,schemasandversionscannot produce this null. The new test orphans a function, type, table, trigger and policy by deleting theirpg_namespacerow and checks that the rest of the snapshot still loads.The
functionsquery also gets anorder by f.oid. It had no ordering, so the join change reshuffled the overloads hover lists. Ordering by oid makes that deterministic, and thebuiltin_maxhover snapshot is updated to match.This is an alternative to #844. It fixes the queries at the source and leaves
Snapshot::loadunchanged, rather than also loading most snapshot parts leniently.Fixes #842