Skip to content

perf(export): start an export from the catalog's row estimate, not an exact count - #4579

Open
datlechin wants to merge 3 commits into
mainfrom
perf/export-catalog-row-estimate
Open

datlechin wants to merge 3 commits into
mainfrom
perf/export-catalog-row-estimate

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • An export no longer runs an exact COUNT(*) of every table before it reads a row. On PostgreSQL and InnoDB that count is a full scan, so the first exported byte waited on a second read of every table.
  • The progress total now comes from the catalog estimate for every engine: one schema-wide read (fetchAllTableMetadata) where the driver has one and the export holds two or more tables of that schema, else the per-table fetchApproximateRowCount. The total is marked as an estimate.
  • The total follows the row scope: a row limit caps a table's share at the limit, and a filter leaves the export with no total, so the bar is indeterminate and counts rows done. A table with no estimate (SQLite, a never-analyzed table) adds nothing; when nothing is known the bar is indeterminate.
  • Tests that pinned the count on purpose are updated: ExportServiceRowCountTests (rewritten for the estimate), ExportServiceStopTests (a Stop during the estimate read), and ReadOnlySafeModeEntryPointTests (an export at Read-Only runs no count).

Measured

PostgreSQL 17.12 in Docker on this Mac, server time:

Before the first row Before (COUNT) After (catalog)
10M-row table 2,127 ms cold, 1,173 ms warm 15 ms (pg_class.reltuples)
1,000 tables of 5,000 rows 20 statements, 1,127 ms 1 statement, 195 ms

The before interval grows with table size; the after one does not. The 1,000-table read is the schema-wide metadata read, which also reads relation sizes.

Test plan

  • ExportServiceRowCountTests: no COUNT( statement for a table export, total is the estimate, a limit of 1,000 on a 10M estimate totals 1,000, a filter leaves no total, a missing estimate leaves no total, two tables of one schema take the schema-wide read once, estimates saturate at Int.max.
  • ExportServiceStopTests, ReadOnlySafeModeEntryPointTests, ExportServiceRedisTests, ExportServiceDataSourceTests, TransferProgressTests, ExportServiceTimeoutTests.

Closes #4552

… exact count

The progress total took a COUNT(*) of every table before the first row, a full scan on
PostgreSQL and InnoDB. It now comes from the catalog estimate, read once per schema where the
driver has a schema-wide read, capped by a row limit and left unset under a filter or when a
table has no estimate.

This branch has not been deployed

No deployments
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(export): start an export without an exact count of every table first

1 participant