Skip to content

perf(grid): read less on table open, save and query-tab SELECT - #4458

Merged
datlechin merged 31 commits into
mainfrom
perf/table-open-save
Nov 23, 2026
Merged

datlechin merged 31 commits into
mainfrom
perf/table-open-save

Conversation

@datlechin

@datlechin datlechin commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Perf audit 2026-11-22b, table-open-save lane: findings 10 and 22, items TOS-A to TOS-I, decisions D8 and D9.

  • TOS-A: a table's DDL is read for CHECK value lists only where it can state one. A curated capability, readsCheckListsFromDDL, is off for PostgreSQL, PGlite, MySQL, MariaDB, SQLite, SQL Server, ClickHouse and DuckDB, whose stored DDL never matches the parser or whose driver answers itself. Every other engine, curated or not, keeps the read.
  • TOS-A: SQLite's driver fills allowedValues from the CREATE statement it already reads: col IN ('a', 'b') as a column or table check, any name quoting, ASCII case folded. A column with two such lists gets none. A list with anything but quoted literals and bare NULLs gives no picker on either parser, so a numeric list no longer offers blank entries.
  • TOS-B (D8): a query tab counts nothing. The paging commands and their menu items do nothing on a query tab, where a page reload wrote a generated table query over the user's SQL. Fetch All asks without a number, and Share Result takes the result's own total.
  • TOS-C: after a save, a total at or past the count threshold stays as an estimate instead of a capped recount that blanked it. A smaller total is counted again as before.
  • TOS-D: the definition read is columns, view answer and keys. The row estimate moved into the count, read only after a definition read, for an unfiltered tab with no exact total, and never twice on an engine whose plan reads it. A keyless relation the live, current, not refreshing catalog lists as a table, by name bytes, is not asked whether it is a view. A restored tab's kind does not count.
  • TOS-E (D9): a table's foreign keys come from the schema's bulk read once it landed, never while a definition change is applied or reread, and as none only for a name the catalog lists.
  • TOS-F: a capped PostgreSQL read through executeUserQuery (a read with parameters, Share Result) runs to its end and decodes only cap + 1 rows, where it decoded up to 5,000,000. An INSERT ... RETURNING still writes and counts every row.
  • TOS-F: the editor's bounded read, drained instead of cancelled inside the user's block, now fails on an error past the cap instead of returning the kept rows.
  • TOS-G: the savepoint probe runs right before a BEGIN or START, the user's or the host's own (Manual Commit, an agent's guard), once per connection, in that statement's generation. The first editor read no longer waits for it, and a session that starts with BEGIN gets the cursor read in that block.
  • TOS-H: MySQL keeps its database proof across the driver's own START TRANSACTION and a COMMIT or ROLLBACK, so the page reload after a save sends no USE.
  • TOS-I: a capped SQLite read with parameters stops in the step loop. A statement that writes runs to its end, locally and through the SSH agent, so a deferred constraint it breaks fails it instead of returning rows its rollback took back.

Measurements

Mac mini, interleaved before, after, after, before. Before is the audit base 9d0d481cf1 (Release, universal); after is this branch at 5cebd5a (build.sh app arm64 --unsigned), on top of #4445. Load1 22 to 250 while other lanes built, so the table holds statement counts and depth, which load does not move. db-roundtrips --sessions main, count phase through the 0 ms proxy, wall phase at 200 ms RTT.

Action Before After
PostgreSQL open_table, statements 11, 11 7, 7
PostgreSQL open_table_second 10, 10 4, 4
PostgreSQL open_table_nopk 12, 12 7, 8
PostgreSQL editor_query 10, 9 2, 2
PostgreSQL editor_query, depth after Run at 200 ms 6 (1,956 ms) 1 (546 ms)
PostgreSQL open_table, depth after the click at 200 ms 6 2
PostgreSQL edit_save, statements after COMMIT 3, 3 2, 2
MySQL open_table 13, 13 10, 12
MySQL editor_query 12, 10 6, 6
MySQL edit_save (no USE, no count) 8, 8 6, 6
MySQL refresh 11, 11 10, 10
  • Gone from open_table on PostgreSQL: the DDL read (constraints_table, table_props_table) and the table's own FK read (fk_table). The estimate stays, read once by the count.
  • MySQL open_table_second, open_table_nopk and editor_commit windows misattributed in both builds under this load (1 and 10, 6 and 0); they are left out.
  • PostgreSQL edit_save sends the savepoint probe before its BEGIN (2 statements before the write, was 1), once per connection; the count after COMMIT is gone, so the depth stays 5.
  • A filter applied after a save on rt_orders (100,000 rows, the count threshold) runs no count now: the save keeps "~100,000", and a filtered table at the threshold is not counted automatically, as on a fresh open.

Parameterized read, SELECT * FROM bench_typical WHERE id > :min (1,000,000 rows, cap 100,000), dt.py tp-session-grid --only-ph02 with the Run pressed twice (a lane copy of the harness), n=2 each:

Before After Same text without parameters
Instructions 12.62, 12.56 G 6.35, 6.28 G 3.0 to 3.6 G
Footprint growth 521, 472 MB 167, 167 MB 172 MB

Tests changed on purpose

  • ShareResultRequestTests: "A result cut short sends its exact count" and "An estimate above the rows held stands in for the total" become "A query result cut short shares no total, though the tab holds a count of the table" and "A whole query result is its own total, though the tab holds a count of the table" (D8).
  • QueryExecutorTests "parseSchemaMetadata maps columns, foreign keys, primary keys" and two empty-input cases drop their estimate assertions: the definition read no longer carries one (TOS-D). Fixtures in ParseSchemaMetadataTests, SchemaMetadataGeneratedColumnTests, Phase2WorkCancellationTests and CatalogChangeWindowTests drop the field.
  • LibPQStopBeforeStatementTests "A Stop during the savepoint probe sends none of the user's statement and reports cancelled" runs the user's BEGIN instead of a read, same expectation (TOS-G). "A Stop during the cursor read's savepoint..." gets its probe from that BEGIN.
  • MySQLDatabaseMoveScanTests "Anything else proves nothing" no longer lists COMMIT (TOS-H).

Deliberately not fixed here

  • TOS-C's keep path, an exact total kept after a save of updates only: cut after review. A count can change without a trigger the app lists: SQLite's ON CONFLICT REPLACE, a PostgreSQL rule, a row-level security policy, a trigger list kept from a refresh whose trigger read failed.
  • TOS-F's stop at the source: cut after review. Stopping at the cap takes a cancel, which rolls back what the statement writes through a function, a view or RETURNING. A capped read with parameters still drains on the wire; it decodes only cap + 1 rows.
  • The editor's capped PostgreSQL text read cancels at the cap as before, so a SELECT whose function or view writes loses those writes outside a transaction. Older than this PR; listed in the follow-up.
  • MariaDB CHECK pickers, the first Run on a restored tab with parameters, Refresh blanking a large total, and iOS dropping allowedValues: found by the plan, outside this lane.

Test plan

  • verify.sh build and verify.sh plugins pass; PluginMetadataCuratedParityTests passes with every plugin built.
  • verify.sh test, the whole Unit plan: 33,484 run, 0 failed.
  • verify.sh ios SQLiteDriverFileTests ExportTwinNameTests QueryCompletionCatalogTests: 66 pass (the SQLite plugin compiles into the iOS app).
  • New: the DDL read per engine (CheckListDDLReadTests), the SQLite CHECK parser (SQLiteCheckValueListTests, SQLiteCatalogReadsTests), query tabs counting nothing and paging untouched (QueryTabCountsNothingTests), the save effect (SavedRowsCountEffectTests), keys before the estimate, the catalog's view vouching and listed FKs (DefinitionReadEstimateTests, SchemaForeignKeyStoreTests), composite FK parity (PostgreSQL, SQLite), capped reads, drains and the savepoint probe on the scripted server (LibPQCappedUserReadTests, LibPQSavepointProbeTests), SQLite capped writes locally and through the SSH agent, the MySQL save proof.
  • Codex: adversarial review, then review rounds 2 to 9; the last is clean.

Docs: TableProApp/docs#277

…and reread a catalog whose schema list failed
…he SQL Server connect as it was; move completion facts with a schema switch
…r's transaction, and reread a hierarchical catalog whose read failed
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