Repository navigation
Deduplicate shared dependencies in LoadTypes - #2686
Merged
Merged
Conversation
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.
When several composite fields use the same type,
LoadTypesrepeatedly expands their shared dependencies before the finalGROUP BY. Eight nested composites with four fields at each level produce 233,000 recursive rows for eight types.Use
UNIONfor the recursive step to visit each(parent, child, depth)tuple once. This reduces that example to 44 rows while preserving the maximum depth used for child-first registration. Add a round-trip test with shared domains, enums, composites and arrays, plus benchmarks for nested types and independent enums.Local benchmark medians on PostgreSQL 18.6, Go 1.25.4, darwin/arm64 (six alternating before/after runs, 20 iterations each; connection and type creation excluded):
The independent-enum case pays a small deduplication cost. The improvement is for shared dependency paths.
Related to #2183. The reporter's schema is unavailable, so this does not establish the cause of their reported slowdown or database crash.
Validation:
go test -race ./...completed with one existing DNS-dependent failure,TestConnectFailsWithResolveFailureAndFailedConnectionAttempts. The original source fails identically because this environment resolvesfoo.invalid. The rest ofpgconnpassed when that test was excluded; all other test packages passed.go test -race . ./pgtypepassed.AI proposal prepared with Codex (GPT-6). The task was to find a reproducible type-loading performance problem, preserve dependency registration, and verify the change with database tests and before/after benchmarks.