Repository navigation
perf(paging): seek on the primary key for next, previous and last page - #4604
Merged
Merged
Conversation
A table page after the first was read with OFFSET, so page N cost about N times page 1. When the page order is the primary key and the engine enforces it (MySQL, MariaDB, PostgreSQL, SQLite), Next, Previous and Last now seek past the edge row on screen, reading backward and flipping the rows for Previous and Last. Everything else keeps OFFSET.
datlechin
enabled auto-merge (squash)
November 26, 2026 04:22
# Conflicts: # apple/TablePro/Core/Coordinators/QueryExecutionCoordinator+SingleRun.swift # apple/TablePro/Core/Plugins/PluginMetadataRegistry+CuratedDefaults.swift # apple/TablePro/Core/Plugins/PluginMetadataRegistry+KingbaseESDefaults.swift
…d tabs and history A PostgreSQL inheritance parent, a SQLite REAL key and column names that differ only in NFC or NFD spelling keep the offset.
…ollated SQLite keys The key answer is asked before each keyed read instead of cached.
datlechin
disabled auto-merge
November 27, 2026 15:08
datlechin
enabled auto-merge (squash)
November 27, 2026 15:08
datlechin
disabled auto-merge
November 27, 2026 15:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OFFSET, so page 5,000 and the last page cost about what page 1 costs. Next readsWHERE key > <last key on screen> ORDER BY key LIMIT n; Previous and Last read in reverse key order and the rows are flipped back before they reach the grid.seeksKeyedPages, is true for MySQL, MariaDB, PostgreSQL and SQLite only and survives plugin registration. Redshift, Snowflake and BigQuery accept duplicate keys, and KingbaseES opts out of the copy it takes from PostgreSQL.OFFSET: Go to Page, page 1, a sort on other columns, tables without a key, views, browse search, and plugins that write their own page queries.TIMESTAMP, masked cells, number-like text in SQLite, untyped SQLite columns, text holding a NUL (standard escaping drops it) and keys the catalog says can hold NULL fall back toOFFSET. That includes SQLite's loneINTEGERkey:INTEGER PRIMARY KEY DESCis not the rowid and takes NULL, and the catalog reports both the same.Test plan
TableKeysetPageQueryTests: the SQL for next, previous, last, descending and composite keys, filters kept in their parentheses, and every refused literal.PaginationCoordinatorTests: next, previous, back to page 1, last, a jump, an unkeyed table, Redshift, a nullable key, a masked key, rows of another page, and re-reads at the offset.MainContentCoordinatorSortTests/backwardPageIsFlipped: a run of the backward statement through a recording driver comes back in key order, and any other statement is left as it arrived; it fails with the flip removed.PluginMetadataRegistryCuratedCapabilityTests: which engines seek, and that the flag survives registration.PaginationCoordinatorTests/nullableKeyKeepsTheOffsetnow expects a nullable loneINTEGERkey to keep the offset, on purpose: the rowid shortcut is gone.TableKeysetPageQueryTests/refusesWhatCannotSeekadds a text key holding a NUL.verify.sh lintPASS. Build and tests not run locally: the PR is blocked on the findings below, and the shared Mac's disk is below the build floor. CI's macOS Tests runs them on this push.Open, blocks merge
Codex round 2 and the security pass, on the branch with the fixes above:
standard_conforming_stringsdiffering between the two, a text key holding\'closes the literal early and runs the rest as SQL. Needs the key bound as a parameter, or a literal form that does not depend on the session (E'...').content.query, which saved tabs and query history store. A table keyed by tokens or session ids writes one to disk on Next. Needs the key kept out of the stored query.NUMERICkey holding a REAL near an integer prints as1.0on older SQLite, soid > 1.0reads the edge row again. Accepting only digit-only decimal text closes it;DECIMAL(10,2)keys then keep the offset.Stringequality, which joins NFC and NFD spellings PostgreSQL and SQLite keep apart.Closes #4526