Skip to content

Deduplicate PK/FK classification SQL (share the CTE form)#124

Merged
nkcoder merged 1 commit into
mainfrom
enhancement/119-dedup-pkfk-classification
Jul 3, 2026
Merged

Deduplicate PK/FK classification SQL (share the CTE form)#124
nkcoder merged 1 commit into
mainfrom
enhancement/119-dedup-pkfk-classification

Conversation

@nkcoder

@nkcoder nkcoder commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Closes #119.

What changed

ListColumns classified PK/FK with correlated EXISTS subqueries per column, while FetchDatabaseMetadata used a faster CTE + LEFT JOIN for the same rule — two implementations that drift, with the slower form in the per-table path.

Extracted a single columnClassificationSQL (the CTE + LEFT JOIN form) shared by both paths:

  • $1/$2 = schema/table; passing NULL/NULL selects every user-schema table (whole-DB mode, used by FetchDatabaseMetadata) and excludes system schemas.
  • Passing a concrete schema/table scopes to that one table (per-table mode, used by ListColumns).

The system-schema exclusion applies only in whole-DB mode, so per-table results are byte-for-byte unchanged.

Acceptance criteria

  • A single PK/FK classification query is used by both paths
  • The retained form is the CTE/LEFT JOIN variant
  • Introspection results unchanged; integration tests pass

Testing

  • TEST_DB_URL=... go test . — pass (unit + integration)
  • Verified PK and FK classification against the demo DB (integration test only asserts PK)

ListColumns used correlated EXISTS subqueries per column while
FetchDatabaseMetadata used a faster CTE + LEFT JOIN for the same rule.
Extract a single parameterized columnClassificationSQL (CTE form) used
by both paths: NULL/NULL selects every user-schema table (whole-DB),
schema/table scopes to one table. Per-table results are unchanged.

Closes #119
@nkcoder nkcoder merged commit 7720689 into main Jul 3, 2026
2 checks passed
@nkcoder nkcoder deleted the enhancement/119-dedup-pkfk-classification branch July 3, 2026 10:09
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.

Deduplicate PK/FK classification SQL (share the CTE form)

1 participant