Skip to content

postgres: support per-column statistics target#14

Draft
ilyalavrenov wants to merge 1 commit into
hex-forkfrom
ilavrenov/introspect-statistics-target
Draft

postgres: support per-column statistics target#14
ilyalavrenov wants to merge 1 commit into
hex-forkfrom
ilavrenov/introspect-statistics-target

Conversation

@ilyalavrenov

@ilyalavrenov ilyalavrenov commented May 18, 2026

Copy link
Copy Markdown

what

new statisticsTarget option on @Column() (postgres only). emits ALTER COLUMN ... SET STATISTICS N on createTable, addColumn, and changeColumn. loadTables reads pg_attribute.attstattarget so migration:generate diffs correctly.

@Column("int", { statisticsTarget: 1000 })
hotColumn: number;

why

so SET STATISTICS lives at the entity, not in a one-off migration. drop/recreate of an annotated column re-applies the target on the next migration:generate instead of silently reverting to cluster default.

threads a `statisticsTarget` option through ColumnOptions / ColumnMetadata /
TableColumnOptions / TableColumn so entities can declare a per-column planner
statistics target:

  @column("int", { statisticsTarget: 1000 })
  hotColumn: number;

PostgresQueryRunner:
  - loadTables: reads pg_attribute.attstattarget; treats pg's -1 sentinel as
    "no override" so the diff doesn't fire on every column.
  - createTable: emits follow-up ALTER ... SET STATISTICS per column with a
    target (CREATE TABLE can't carry it inline).
  - addColumn: same.
  - changeColumn: diffs old vs new statisticsTarget and emits up/down ALTERs,
    mapping null/undefined to -1 (cluster default) on the reset path.

postgres only; other drivers pass the option through without using it.

tests: 4 functional cases against live postgres 14 (createTable round-trip,
changeColumn diff, reset to default, addColumn). adjacent columns-comments
suite still green.
@ilyalavrenov ilyalavrenov force-pushed the ilavrenov/introspect-statistics-target branch from 9f3b5d4 to b9f6b87 Compare May 18, 2026 16:44
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