Repository navigation
Done
Labels
enhancementNew feature or requestplatform-macosAbout the macOS apprustPull requests that update rust code
Description
Problem
Every page of a table tab after the first skips rows with OFFSET. The server produces and discards every skipped row, so page N costs about N times page 1. Last Page on a 10M-row table walks about 10M rows. The first page, which the 228-275 ms table-open measurement covers, is not affected.
Cause
buildPaginationClausealways emitsLIMIT n OFFSET k, orOFFSET k ROWS FETCH NEXT n ROWS ONLY(apple/TablePro/Core/Services/Query/TableQueryBuilder.swift:306-314).- Next, previous, last page and go-to-page only change
currentOffset(apple/TablePro/Core/Coordinators/PaginationCoordinator.swift:25-46;apple/TablePro/Models/Query/QueryTabState.swift:381-411). - A table tab already orders by its primary key by default.
defaultSortBehavioris.primaryKey, ascending (apple/TablePro/Models/Settings/AppSettings.swift:131-132), andDefaultSortResolverturns it into a sort on the key columns (apple/TablePro/Core/Services/Query/DefaultSortResolver.swift:19-35). So the page query carriesORDER BY <pk>, which is all a seek needs. It is never used to seek. - With the setting at None, or a plugin hint of
suppress, a LIMIT dialect gets no ORDER BY at all (TableQueryBuilder.swift:287-322). The PostgreSQL plugin turns offsynchronize_seqscansto keep unordered pages stable (apple/Plugins/PostgreSQLDriverPlugin/LibPQDriverCore.swift:335-347). - The core already pages this way for Windows and Linux.
paging_modepicksKeysetfor a table with a unique key and no user sort,CtidWindowfor a PostgreSQL table with no key, andOffsetotherwise (core/crates/core/src/browse/paging_mode.rs:31-45).keyset_walkseeks past the edge row's key and reverses the order for the last page (core/crates/core/src/browse/build_page.rs:122-170). The Mac's Swift builder does not follow that rule.
Change
- The same rule on both sides. Follow the core's paging rule in the Mac's
TableQueryBuilder, until each engine's page read moves to the core and the Swift builder goes. - Next and previous. With an order that ends in a unique key, seek:
WHERE (k1, k2) > (:last1, :last2) ORDER BY k1, k2 LIMIT nfor the next page, and the mirrored comparison in reverse order for the previous page.- The page keeps the key of its first and last rows.
- The app's default primary-key sort counts as the key order, not as a user sort.
- Last page. Read it in reverse key order with
LIMIT, then flip it. - A user's own sort. Seek on the tuple (sort columns..., key), with the key as the tiebreaker, using row-value comparison where the engine has it (PostgreSQL, MySQL 8, SQLite 3.15 and later). Nullable sort columns need an explicit NULLS rule, so the seek and the ORDER BY agree.
- The core's
paging_modesends every user sort toOffsettoday. Change it the same way, so the rule stays one rule.
- The core's
- Where OFFSET stays. A direct jump to page N in the middle, a table without a unique key, and views keep
OFFSET. PostgreSQL tables without a key can use the core's ctid window.
Measure
- A 10M-row table on PostgreSQL, MySQL and SQLite: time page 1, page 5,000 and the last page, before and after, with
EXPLAIN (ANALYZE, BUFFERS)on PostgreSQL and rows examined in the MySQL slow log. Expected: every keyed page costs about what page 1 costs. - The same with a user sort on a non-unique column: the seek returns the same rows, in the same order, as the offset query it replaces (a test per dialect, with NULLs in the sort column and ties across a page edge).
Part of the performance plan.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestplatform-macosAbout the macOS apprustPull requests that update rust code
Activity
datlechin commentedon Nov 26, 2026
The first part of this ships in #4604: Next, Previous and Last page seek on the primary key when the page order is that key, on MySQL, MariaDB, PostgreSQL and SQLite. What is left:
ORDER BYagree. Until then a sort on any column other than the key pages byOFFSET.paging_modeincore/crates/core/src/browse/paging_mode.rsstill sends every user sort toOffset. Change it with the item above, so the Mac and the core keep one rule.OFFSET.INTEGER PRIMARY KEY DESCcolumn holding NULL, a Last page read with an exact count gone stale, and Previous after another session deleted the rows before the page, which can give a short page and then an empty one.