Repository navigation
Done
Labels
Description
Problem
On a SQL engine, an export reads no row until it has run an exact COUNT(*) of every table and view it will export. On PostgreSQL and InnoDB that count is a full scan, so a whole-database dump reads every table twice and the time to the first exported byte grows with table size. A view's count runs the whole view. The count only sets the progress bar's total, and for a filtered or limited export that total is wrong, because the count ignores the row scope. Not measured yet.
Cause
ExportServiceawaitsfetchTotalRowCountbefore it callsplugin.export(apple/TablePro/Core/Services/Export/ExportService.swift:227-235,:282).- For SQL engines it builds
SELECT COUNT(*) AS c FROM <table>joined withUNION ALL, 50 tables per statement (ExportService.swift:576-610). When a chunk fails, each of its tables is counted again on its own (:596-609). - The count ignores
ExportObjectItem.rowScope, which the export hands the plugin (:275). - Non-SQL engines already take the catalog estimate through
fetchApproximateRowCountand mark the total as an estimate (:553-574). The streaming query export does the same (:357,:412-424). - The drivers already read a schema-wide row estimate in one statement:
fetchAllTableMetadatawithprovidesBulkTableMetadataFetch(apple/Plugins/TableProPluginKit/PluginDatabaseDriver.swift:371-372). On PostgreSQL it comes frompg_class.reltuples(apple/Plugins/PostgreSQLDriverPlugin/PostgreSQLPluginDriver+BulkMetadata.swift:89-110). - The progress view already handles a missing or estimated total. A total of 0 becomes
niland shows an indeterminate bar (apple/TablePro/Views/Components/TransferProgress.swift:155). An estimate stops at 95% (:173).
Change
- Remove the
COUNT(*)path fromfetchTotalRowCount. No export waits on a table scan before its first row. - Take the total from the catalog estimate for every engine. Read it once per schema through the bulk table metadata read where the driver has one. Otherwise use the per-table
fetchApproximateRowCount. SetrowTotalIsEstimate. - Respect the row scope:
- With a row limit, the total is the smaller of the limit and the estimate.
- With a filter, there is no total. Progress shows rows done.
- With no estimate (SQLite, views, an engine that returns
nil), leave the total unset, so the bar is indeterminate and the label counts rows done. - Progress stays driven by rows the plugin reports. Nothing new caps or limits the export.
Measure
- Add an os_signpost from the Export click to the first row the plugin receives. Run it on a 10M-row PostgreSQL table, a 10M-row InnoDB table and a 1,000-table PostgreSQL schema. Before: the interval includes a full count scan of every table. After: one catalog statement per schema, and the interval does not grow with table size.
- Server side:
pg_stat_statements(PostgreSQL) andperformance_schema.events_statements_summary_by_digest(MySQL) show noCOUNT(*)statements during an export. - An export with a row limit of 1,000 on a 10M-row table shows a total of about 1,000.
Part of the performance plan.
Activity