Skip to content

Deduplicate shared dependencies in LoadTypes - #2686

Merged
jackc merged 1 commit into
jackc:masterfrom
Grivn:fix/loadtypes-shared-dependencies
Oct 17, 2026
Merged

jackc merged 1 commit into
jackc:masterfrom
Grivn:fix/loadtypes-shared-dependencies

Conversation

@Grivn

@Grivn Grivn commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

When several composite fields use the same type, LoadTypes repeatedly expands their shared dependencies before the final GROUP BY. Eight nested composites with four fields at each level produce 233,000 recursive rows for eight types.

Use UNION for 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):

Case Before After
53 independent enums 2.591 ms 2.707 ms
4 nested composites 2.831 ms 2.657 ms
8 nested composites 115.432 ms 3.213 ms

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 1.25.4: go test -race ./... completed with one existing DNS-dependent failure, TestConnectFailsWithResolveFailureAndFailedConnectionAttempts. The original source fails identically because this environment resolves foo.invalid. The rest of pgconn passed when that test was excluded; all other test packages passed.
  • Go 1.27.2: go test -race . ./pgtype passed.
  • The new test passes with all five query execution modes. Existing geometric-codec and array-delimiter tests also pass.

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.

@jackc
jackc merged commit 69ac984 into jackc:master Oct 17, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants