Skip to content

perf(query): read table definitions once and bound automatic row counts - #4330

Merged
datlechin merged 7 commits into
mainfrom
perf/table-load-pipeline
Nov 18, 2026
Merged

datlechin merged 7 commits into
mainfrom
perf/table-load-pipeline

Conversation

@datlechin

@datlechin datlechin commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • P1: table load traces record lease acquired, pin finished, first row, phase 2 begin and phase 2 end. The history file gains optional keys, so the previous stable still reads it.
  • P7: a table without a primary key keeps its definition across pages once phase 2 has read it.
  • P8: a first open that reads columns before its rows hands that read to the definition read, so columns are fetched once.
  • P10: phase 2 stops when a tab leaves its table or closes. A page, sort, refresh or pinned result keeps it. Cancellation lands between statements: a server cancel can arrive after the lease is released and hit the next statement.
  • P11: an automatic count with no estimate reads at most the threshold plus one row. Always count stays exact.
  • P11: a total, a count past the cap or a failed count is kept per relation and filters until the filters change or the tab refreshes.
  • P11: Oracle and Dameng report NUM_ROWS as the estimate. Spanner, Cloudflare D1 and SurrealDB are counted only on request.

Test plan

  • New: TableLoadTraceSummaryTests, TableLoadPerformanceRecordTests, FirstLoadColumnReadTests, Phase2WorkCancellationTests, TableQueryBuilderCappedCountTests, RowCountPlanTests, FKNavigationTests.metadataCacheCoversTablesWithoutPrimaryKey.
  • With the P1, P7, P8, P10 and P11 fixes reverted together, the new tests for each failed.
  • Updated on purpose: RowCountPlanTests.unfilteredUnknownSize and filteredUnknownSize now expect the capped count. ExactRowCounterTests uses Oracle as its default engine, because Spanner no longer falls back to the host count.
  • Measured locally, median of 5, exact against capped count on a view with no estimate:
Engine Rows COUNT(*) Capped at 100,001
PostgreSQL 17.11 2,000,000 56.0 ms 9.2 ms
MariaDB 13.0.2 1,000,000 378.8 ms 52.8 ms
  • FirstLoadColumnReadTests counts fetchColumns: 1 per open with the reuse, 2 without it.

Needs the maintainer

  • Oracle, Dameng and SurrealDB are registry plugins: their estimate changes reach users when those plugins are next published.

@datlechin
datlechin enabled auto-merge (squash) November 18, 2026 17:25
@datlechin
datlechin merged commit 2531923 into main Nov 18, 2026
11 checks passed
@datlechin
datlechin deleted the perf/table-load-pipeline branch November 19, 2026 02:01
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