Skip to content

feat: cost schema the production snapshot doesn't cover via the synthesizer#184

Open
veksen wants to merge 2 commits into
mainfrom
feat-sync-production-stats
Open

feat: cost schema the production snapshot doesn't cover via the synthesizer#184
veksen wants to merge 2 commits into
mainfrom
feat-sync-production-stats

Conversation

@veksen

@veksen veksen commented Jul 17, 2026

Copy link
Copy Markdown
Member

Goal

The analyzer side of Production Statistics (Site feat-sync-production-stats, ADR 0004). Makes the core synthesizer actually run on the connected and CI costing paths, so a table the production snapshot has never seen is costed with a real row count and column selectivity instead of the flat 10M default.

CI will fail on npm install until @query-doctor/core@0.13.0 is published (this needs the Site branch on staging first). Expected — this branch is staged ahead of that publish.

What

Before: QueryOptimizer.setStatistics built Statistics without the current schema, so an uncovered table fell to the default. After: the schema is passed in, so uncovered tables are sized by the synthesizer (FK graph → shape class → DB-median) with type/constraint-inferred column stats. Both connected and CI paths already thread the schema through onSuccessfulSync → optimizer.start, so the single wiring change covers both.

How

  • query-optimizer.ts: pass schema as the 5th Statistics arg (the only new Statistics in the repo); add a syntheticTables getter mirroring computedStats/ownMetadata.
  • reporter.ts / runner.ts: plumb the synthesized-table set onto ReportContext.modeledTables.
  • package.json: bump @query-doctor/core to ^0.13.0 (the minor that adds currentSchema + syntheticTables).

Deferred (follow-up, same branch)

Rendering the "modeled, not verified" banner in the PR comment (template + buildViewModel + snapshot regen). Left until core publishes so the template and snapshot tests can be validated rather than written blind.

Sequencing

  1. Site feat-sync-production-stats → staging → core publishes 0.13.0.
  2. Here: npm install reconciles the lockfile, CI goes green, then the comment-render follow-up.

veksen and others added 2 commits July 16, 2026 23:02
…esizer

Pass the current schema into Statistics in QueryOptimizer.setStatistics, so a
table the exported production snapshot doesn't cover — added on this branch, or
since the snapshot was captured — is sized by core's synthesizer (foreign-key
graph, shape class, column inference) instead of the flat default. Both the
connected and CI paths already thread the schema through
onSuccessfulSync -> optimizer.start, so this one change covers both.

Expose the synthesized-table set (QueryOptimizer.syntheticTables) and plumb it
onto ReportContext.modeledTables for the run report. Rendering it in the PR
comment (a 'modeled, not verified' banner) is the follow-up, done once core
publishes so the template and snapshot tests can be validated.

Requires @query-doctor/core >= 0.13.0 (the currentSchema parameter and
syntheticTables); the dep is bumped but the lockfile can't reconcile until that
version is published. CI will fail on install until then — expected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Integration test (testcontainers, mirroring query-optimizer.test.ts): a table
absent from the exported snapshot but present in the schema — foreign-keyed to a
covered table sized at 1M — is reported in syntheticTables and costed from the
snapshot, not its single branch row. Proves setStatistics forwards the schema so
core's synthesizer engages.

Can't run until @query-doctor/core@0.13.0 publishes and deps install; staged to
validate when the branch is closed out post-publish, alongside the deferred
comment-render.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant