Skip to content

perf(export): start an export without an exact count of every table first #4552

Done

Description

@datlechin

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

  • ExportService awaits fetchTotalRowCount before it calls plugin.export (apple/TablePro/Core/Services/Export/ExportService.swift:227-235, :282).
  • For SQL engines it builds SELECT COUNT(*) AS c FROM <table> joined with UNION 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 fetchApproximateRowCount and 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: fetchAllTableMetadata with providesBulkTableMetadataFetch (apple/Plugins/TableProPluginKit/PluginDatabaseDriver.swift:371-372). On PostgreSQL it comes from pg_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 nil and shows an indeterminate bar (apple/TablePro/Views/Components/TransferProgress.swift:155). An estimate stops at 95% (:173).

Change

  • Remove the COUNT(*) path from fetchTotalRowCount. 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. Set rowTotalIsEstimate.
  • 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) and performance_schema.events_statements_summary_by_digest (MySQL) show no COUNT(*) 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

  1. added
    enhancement
    platform-macos
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementplatform-macos

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions