Skip to content

perf(export): read a dump's table DDL once per schema - #4592

Merged
datlechin merged 3 commits into
mainfrom
perf/import-lex-once-ddl-bulk
Nov 26, 2026
Merged

datlechin merged 3 commits into
mainfrom
perf/import-lex-once-ddl-bulk

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • A SQL dump reads every plain table's CREATE TABLE once per schema instead of once per table. On PostgreSQL that is 2 catalog statements for the schema in place of 3 per table.
  • PluginKit gains PluginExportBulkReads.tableDDL, PluginDatabaseDriver.fetchAllTableDDL(schema:) and PluginExportDataSource.fetchAllTableDDL(databaseName:), each with an empty default. Additive; the kit is already 47, one past the 46 that v0.89.0-beta.1 shipped, so no bump.
  • The PostgreSQL read covers plain tables that are not partitions, and renders each with the same PostgreSQLTableDDL.script and the same column and constraint text as the per-table read. A partitioned table, a partition, a view or a table the read leaves out is read alone, so its text is unchanged.
  • Both constraint reads now break a tie between two constraints of one kind by name, so the per-table and schema-wide reads list them in the same order rather than in whatever order each plan returns.
  • SQLExportGroupReads.tableDDL(for:) takes the group answer and falls back to the table's own read for a table the group leaves out or a group read that fails.

Measured

PostgreSQL 17.12 in Docker on this Mac, a schema of 1,000 tables, server time:

Structure phase reads Before After
Statements 3,000 (3 per table) 2
Server time 1,030 ms 13 ms

At +50 ms RTT the before reads are about 3,000 round trips, about 150 s; the after reads are 2.

Test plan

  • PostgreSQLCatalogExportTests: the schema read sends exactly the two statements, and for each table of the fixture (with constraints, without, unlogged) its text equals fetchTableDDL on the same catalog rows; the predicate leaves out partitions where the server has them.
  • SQLExportGroupReadTests: a dump reads the group once and reads alone only the table the group left out, with the same dump text and warnings as table-by-table reads; a failed group read falls back to every table's own read.

Not in this PR, left on the issue: one lex per imported file with classified units, and the UTF-8 byte scanner.

Closes #4555

A SQL dump read each table's CREATE TABLE with its own catalog queries, three round trips per
table on PostgreSQL. PluginKit gains a table DDL group read beside the others; PostgreSQL answers
it for every plain table of the schema in two statements, rendered by the per-table renderer, and
a table it leaves out keeps its own read.
@datlechin
datlechin enabled auto-merge (squash) November 26, 2026 01:51
@datlechin
datlechin merged commit 0ddc1f4 into main Nov 26, 2026
11 checks passed
@datlechin
datlechin deleted the perf/import-lex-once-ddl-bulk branch November 27, 2026 16:37
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.

perf(import): lex imported SQL once and read a dump's table DDL per schema

1 participant