Skip to content

[Epic] SQL performance: push the work down to the database on SQL drivers — SQL first, no slow paths kept for driver parity #33631

Open
4 of 4 issues completed

Description

@objectstack-fleet

triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

Filing gate: ④ an epic parent on the maintainer's direct word, verbatim, in the triage seat session on 2026-11-15: 「开一个SQL性能优化专题」「p1」. The governing principle is from the same session: 「有的功能如果Mongo内存不支持,那就不需要支持,首先保sql,应该用最高性能的方案,而不能为了兼容而兼容」. That principle agrees with the driver-memory/driver-mongodb freeze in #5499. Epic parent: tracking, never dispatched; the work lives in the children. ⛔ Not a claim.

维护者速读

目标:在 SQL 驱动(driver-sql 各方言 + Turso)上,把过滤、关联、聚合、权限范围尽量下推给数据库,用性能最高的方案。内存和 Mongo 驱动做不到的能力就在那里明确拒绝,不为兼容保留慢路径。

起点是一个已知的墙:跨对象过滤「先查 id 再 IN」有 1000 上限(#33335、#33619)。专题先做一次盘点和基准测量,找出所有同类的「在应用层做数据库该做的事」的路径,再按收益排序拆卡。

Milestones and children

Milestone Child Blocked-by Lane
M0: measure #33633 inventory and benchmark baseline (filed with this epic) — server (server#5 assigns areas)
M1: the known wall #33626 cross-object where → an in-database semi-join, with no 1000-id cap; non-SQL drivers refuse #33512 (PR) server · A3
M1: the rule #33627 write the SQL-first rule into AGENTS.md, decision analysis, contract review and skills — skills
M2: what M0 finds filed from M0's ranked list #33633 per area
later 5-hop relation paths (an ADR-0071 amendment, once the SQL path exists; analysis on #33619) #33626 spec + server

Rules for children

  • Each child names the SQL shape it produces (JOIN, semi-join, an aggregate in the database), and the measured before/after on the M0 baseline.
  • Security never regresses: every pushed-down hop carries that object's read scope and tenant wall, with a parity test against the current path.
  • A non-SQL driver refuses with a stable code. That is a correct answer under this epic, not a gap to fill.
  • A child that changes an authorable contract (spec) or an ADR follows the usual governed path.

Done when

M0's ranked list is worked down to the items the maintainer accepts. Every pushed-down path then has a before/after on the baseline, and the rule (#33627) has landed.

Sub-issues

Sub-issues

4 of 4 Issues completed
Loading 4 sub-issues

Activity

  1. added
    priority:p1
    tracking
    pm:epic
    domain:server
    on Nov 15, 2026
  2. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · os-elon-musk · session_016WV4d1QwJJ5KGZTThP4fnq

    SQL performance M0 — inventory, baseline and ranked list (#33633)

    Measured 2026-11-15T05:06Z on origin/main @ 4c32b969 (line references below are on that tree). Harness: draft PR #33662 — packages/qa/dogfood/bench/sql-perf/ (bench.mjs = HTTP baseline, micro.mjs = today-vs-target SQL pairs, README). Databases: SQLite through the better-sqlite3 SqlDriver, PostgreSQL 16 (local cluster, fsync=off for loading only). Fixture: bench_region 20 -> bench_account scale/100 (private OWD) -> bench_opportunity scale/10 (controlled_by_parent) -> bench_line_item = scale (controlled_by_parent, lookup bench_product 200). The member owns every 10th account. Iterations 20 (100k) / 10 (1M), warmup 3, shared 4-core box: statement counts are exact, milliseconds are indicative.

    The maintainer picks what M2 files. Nothing here was filed; one reproducible defect (R2) is flagged for the seat to file.

    Ranked list

    # item measured cost (today) expected gain (target, measured by micro.mjs at 1M unless noted) area size
    R1 Per-measure aggregation filter forces the in-memory aggregate: every row of the scoped set is fetched into the app (engine-delete-and-aggregate.ts:1341, :1392) aggregate_measure_filter p50: SQLite 383 ms (100k) / 6.2 s (1M); PG 768 ms / 7.3 s conditional aggregate (sum(case when … end) / PG FILTER (WHERE …)) in the GROUP BY: SQLite 5.10 s -> 0.53 s, PG 5.09 s -> 0.14 s (10x–36x) A4 (engine + driver-sql capability flag); A3 consumer (analytics measures) M
    R2 Analytics dimension through a lookup is an FK-expand: GROUP BY the FK, then id IN (every distinct FK value), then re-bucket in the app (objectql-strategy.ts:1765, :1723) 500 DATABASE_ERROR at 1M on both dialects (100k distinct FKs: SQLite "too many SQL variables"; PG bind count wraps to 34464); 123–131 ms at 100k one JOIN … GROUP BY parent.attr: PG 182 ms -> 131 ms for the first read alone, and it stops failing. SQLite join measured slower (130 -> 363 ms vs the first read only) but the today path does not answer at all A3 (service-analytics) M
    R3 Default list order created_at desc has no index (system column; not in the implicit set, schema-drift.ts:2295) — every default-ordered page sorts its whole filtered set unfiltered admin list p50: SQLite 1.31 s, PG 326 ms at 1M index (created_at, id): unfiltered page SQLite 1237 ms -> 0.09 ms, PG 69 ms -> 0.38 ms; member page PG 110 ms -> 3.1 ms (SQLite's planner keeps the chain-first plan: 146 -> 154 ms) A4 (schema sync implicit indexes) — needs a ruling: the implicit-index ruling excluded system columns for want of a measured read S
    R4 Unrestricted (admin) reads of a controlled_by_parent detail still carry the composed chain fk IN (SELECT id FROM master WHERE fk2 IN (SELECT id FROM master2)) (engine-readable-ids-permission-formula.ts:207 composes ReadableIds.compose(leaf, undefined); leaf from security-plugin-cbp-read-filter.ts:156); the analytics path ANDs the same chain twice rides on every admin list, count and aggregate above (list_filter_sort admin 630 ms SQLite / 238 ms PG at 1M) drop the vacuous leaf: page SQLite 397 -> 281 ms, PG 97 -> 56 ms; total SQLite 217 -> 136 ms, PG 78 -> 54 ms (−29% to −42%, twice per list). Caveat for the decision: the chain also hides orphan details (no master row) A2 (plugin-security leaf) + A4 (engine composition) S–M, needs decision (orphan semantics)
    R5 Cross-object filter ({ opportunity: { stage: 'won' } }) reads the related ids as the caller, then $in (engine-query-lowering.ts:184-217, RELATION_FILTER_ID_CAP = 1000); the id read runs twice per list (page + total) 400 INVALID_FILTER already at 100k (20k matching opportunities > 1000); small match (product.family) p50 PG 328 ms / SQLite 991 ms at 1M a nested subquery leaf, composed like ReadableIds so the related object's read scope still applies: the refused query is served in PG 198 ms / SQLite 376 ms; small match PG 153 -> 122 ms, SQLite 627 -> 615 ms A4 (objectql lowering + driver compile) M
    R6 Non-UTC date bucket forces the in-memory aggregate (ADR-0053 Phase 2 D2, UTC-only native bucketing; engine-delete-and-aggregate.ts:1323-1341) analytics_month_tz p50 at 1M (100k opportunities): PG 694 ms, SQLite 379 ms zone-aware SQL bucket: PG 429 -> 40 ms (11x), SQLite 198 -> 71 ms (fixed-offset only — SQLite has no tz database, so DST zones stay in memory there) A4 — amends ADR-0053 D2 for PG (new ADR status line) M, needs decision
    R7 Cascade delete is one full engine delete/update per dependent (engine-cascade-planning.ts:1085-1171), each with its hooks, recycle-bin capture and probes 155 statements to delete one opportunity with 10 line items (~15 per child), p50 121–237 ms; linear in children per relation: one id read + one DELETE … WHERE fk = ? (or UPDATE … SET fk = NULL) + one batched recycle-bin capture when the child has no per-row hooks; not measured as SQL (needs the batched capture shape first) A4 (engine) + A3 (trash / recycle bin) M–L
    R8 Per-request identity and permission resolution: a plain list is 10 statements, 2 of them data; cold it is ~21 (sys_session x2, sys_user x3–5, sys_member x4 incl. the organization's member list up to 1000 rows a page resolve-authz-context.ts:2406, permission sets x2, positions x2, metadata activation x2). The grants cache exists and is OFF by default (OS_AUTHZ_GRANTS_CACHE_TTL_MS=0) fixed 7–8 statements per request admin, 11–12 member, 29 on a member's record page (record_page member 31 vs 18 admin) on a local database these are ~1–3 ms; on a network database each is a round trip (Turso, managed PG). Not measured over a network A1 (session) + A2 (security) + core authz M
    R9 Sharing read scope materializes sys_record_share.record_id (limit: 5000) into id IN (…) on every member read of a private object (sharing-service.ts:747-764); hierarchy scopes expand owner ids in the app (:742) unmeasured: the fixture holds no shares and no hierarchy (needs a share-seeding leg) id IN (SELECT record_id FROM sys_record_share WHERE …); also removes the 5000-grant ceiling (read-only inference: grants past 5000 look silently dropped, fail-closed — not reproduced, not filed) A2 (plugin-sharing) S–M
    R10 Roll-up summary recompute: per distinct parent per summary field, one aggregate + one full engine update on every child write (engine-summaries-and-expansion.ts:458-470) unmeasured (fixture has no summary fields) one grouped aggregate … WHERE fk IN (…) GROUP BY fk per descriptor + batched parent updates A4 M
    R11 owner_id (the column a private-OWD read filters on) has no index — system column, excluded by the same ruling as R3 small at 10k accounts: account list SQLite 1.6 -> 1.4 ms, PG 1.5 -> 1.3 ms; chain count unchanged grows with private-object size; rides with R3's ruling A4 S
    R12 Every paged list also runs count(*) with the full predicate (protocol-data-crud.ts:803; $count=false opts out) member read-scoped total: PG 35 ms vs the page's 118 ms today becomes the dominant cost once R3 lands (page 3 ms, total 35 ms); a Console that does not need total can send $count=false today E1 (list door) + UI S

    Not ranked (one extra statement, already batched): $expand reads id IN (…) per expanded field per page (engine-summaries-and-expansion.ts:593); master-detail header reads (engine-referential-integrity.ts:514). Turso remote advertises no date granularity, so every bucket there is in memory (driver-turso/src/remote-transport.ts:887) — not measured, no Turso here.

    Inventory (by the card's five categories)

    category site (@4c32b969) trigger SQL shape it should become
    id list, then $in objectql/src/engine-query-lowering.ts:184-217 nested relation condition in any where (find, count, aggregate) correlated / nested subquery leaf (R5)
    id list, then $in plugin-sharing/src/sharing-service.ts:742-764 every member read of a private-OWD object id IN (SELECT record_id FROM sys_record_share …); hierarchy owner set as a subquery (R9)
    id list, then $in service-analytics/src/strategies/objectql-strategy.ts:1765 (resolveFkAttr) analytics dimension through a lookup JOIN (R2)
    id list, then $in core/src/security/resolve-authz-context.ts:2406 every request with an active organization (org member ids for sys_user scoping) membership subquery at the sys_user read (R8)
    id list, then $in objectql/src/engine-summaries-and-expansion.ts:593 $expand / related-list expand LEFT JOIN (not ranked)
    in-memory aggregate objectql/src/engine-delete-and-aggregate.ts:1341, :1392 aggregations[].filter; non-UTC tz + date bucket; a granularity the driver does not advertise FILTER (WHERE …) / CASE WHEN; zone-aware bucket (R1, R6)
    in-memory aggregate engine-delete-and-aggregate.ts:1349 (applyHaving) any having HAVING (small: runs on aggregated rows)
    in-memory join / regroup objectql-strategy.ts:1723 (rebucketCrossObject) analytics cross-object dimension JOIN … GROUP BY (R2)
    N+1 objectql/src/engine-cascade-planning.ts:1085-1171 delete with deleteBehavior: cascade / set_null children per-relation set statements (R7)
    N+1 objectql/src/engine-summaries-and-expansion.ts:458-470 any child write under a roll-up summary grouped aggregate + batched update (R10)
    N+1 objectql/src/recycle-bin/restore.ts:687-702 restore that re-links cleared references one UPDATE … WHERE id IN per field
    N+1 objectql/src/assignment-rules.ts:637-639 load-balanced assignment rule one GROUP BY owner_id count
    N+1 objectql/src/engine-validate.ts:408-418 batch validate / preview (2 reads per submitted row) one id IN (…) read
    N+1 (per request) resolve-authz-context.ts:2402-2408, plugin-auth/src/auth-manager-password-session-policy.ts:183 every authenticated request memoised / cached identity (R8)
    read scope in app sharing-service.ts:674-765 (see above) member reads of private objects SQL predicate (R9)
    read scope (SQL, but vacuous) engine-readable-ids-permission-formula.ts:207; plugin-security/src/security-plugin-cbp-read-filter.ts:156 unrestricted reads of CBP details omit the leaf (R4)
    index driver-sql/src/schema-drift.ts:2286-2310 schema sync authored single-valued lookup / master_detail / user columns DO get idx_TABLE_COLUMN on both dialects (measured in the index listing); multi-valued (JSON) ones cannot
    index gap schema-drift.ts:2295 (SYSTEM_COLUMN_NAMES) schema sync created_at (default order), owner_id (private OWD) carry none (R3, R11); in single tenancy organization_id carried none on the fixture tables either

    Baseline (p50 / p95 ms; statements = the db mark, warm median)

    scenario who stmts SQLite 100k SQLite 1M PG 100k PG 1M
    list_filter_sort admin 10 104 / 125 630 / 694 81 / 105 238 / 294
    list_filter_sort member 14 31 / 37 103 / 128 43 / 53 205 / 263
    list_deep_page admin 10 110 / 149 954 / 1133 85 / 95 314 / 370
    cross_object_filter_small admin 12 128 / 156 991 / 1063 71 / 91 328 / 347
    cross_object_filter_small member 16 40 / 45 139 / 151 45 / 51 191 / 231
    cross_object_filter_large admin 9 400 400 400 400
    aggregate_group_status admin 9 80 / 88 528 / 641 59 / 71 221 / 297
    aggregate_group_status member 11 25 / 29 65 / 77 36 / 41 126 / 132
    aggregate_measure_filter admin 9 383 / 509 6209 / 6463 768 / 888 7303 / 8692
    analytics_cube_status admin 9 82 / 110 763 / 891 48 / 58 194 / 231
    analytics_cube_status member 11 20 / 24 91 / 130 27 / 33 114 / 143
    analytics_cross_object_dim admin 10 131 / 141 500 123 / 158 500
    analytics_month_tz admin 9 48 / 61 379 / 409 90 / 133 694 / 850
    record_page admin 18 37 / 50 93 / 112 29 / 41 27 / 31
    record_page member 31 37 / 45 43 / 63 39 / 44 37 / 46
    scoped_list_unfiltered admin 10 160 / 217 1314 / 1545 78 / 92 326 / 363
    scoped_list_unfiltered member 14 32 / 42 168 / 204 41 / 51 177 / 209
    scoped_account_list member 14 13 / 18 15 / 23 20 / 24 19 / 24
    cascade_delete_opportunity admin 155 122 / 147 139 / 169 237 / 259 193 / 243

    Seed time: SQLite 1.2 s (100k) / 9.3 s (1M); PG 3.7 s / 32.6 s — 1M was measured on both dialects, nothing in the card's five scenarios is left unmeasured. Unmeasured by design of this fixture: sharing grants (R9), roll-up summaries (R10), Turso remote, a network database (R8).

    Flagged for the seat to file (class a, reproduced)

    • R2 — POST /analytics/query with a dimension through a lookup answers 500 DATABASE_ERROR once the base set holds more distinct FK values than the dialect's bind limit. Reach: public door, measured on both dialects: cube bench_line_item, dimensions: ['opportunity.stage'], 100k distinct opportunities -> SQLite too many SQL variables, PostgreSQL bind message has 34464 parameter formats but 0 parameters (100,000 mod 65,536). Seam: service-analytics ObjectQLStrategy#resolveFkAttr (objectql-strategy.ts:1765). Dedupe words: resolveFkAttr, FK-expand bind limit, too many SQL variables analytics, cross-object dimension 500.
  3. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · os-elon-musk · session_016WV4d1QwJJ5KGZTThP4fnq

    Correction to the M0 ranked list (R3, R1, R5, R12) — #33633

    Corrects the ranked-list comment 6889544281 (posted 2026-11-15T05:06Z); that comment is left as it was. Raised by review#2 on #33662. Measured 2026-11-15T05:47Z.

    What was wrong. micro.mjs I8b timed the R3 index on select * from bench_line_item order by created_at desc, id desc limit 50. The engine does not run that statement. The admin default page it emits today still carries the vacuous controlled-by-parent chain (R4). Re-captured at 1M through X-OS-Debug-Timing: json on both dialects: select * from bench_line_item where opportunity in (select id from bench_opportunity where account in (select id from bench_account)) order by created_at desc, id desc limit ?. So the old SQLite figure "1237 ms -> 0.09 ms" was what R3 and R4 buy together.

    Re-measured. micro.mjs as committed in d00725a6 on #33662. Engine tree fbccdf3f, the stamp in the output. 1M line items, median of 7, a shared 4-core box. PostgreSQL 16 ran on a private cluster, now stopped and removed. I8b is now the chained statement; I8c is the unchained one, labelled "with R4". Each reading records the planner's plan before and after the temporary (created_at, id) index.

    row SQLite run 1 SQLite run 2 PG
    I8b admin page, chained (today) 1736 -> 1328 ms 1320 -> 1391 ms 229 -> 0.90 ms
    I8c admin page, with R4 1707 -> 0.09 ms 1183 -> 0.08 ms 62 -> 0.51 ms
    I8 member page 163 -> 179 ms 147 -> 145 ms 101 -> 3.2 ms

    Plans:

    • SQLite, chained: identical before and after, in both runs: SEARCH bench_line_item USING INDEX idx_bench_line_item_opportunity (opportunity=?) … USE TEMP B-TREE FOR ORDER BY. The index is never used. The spread between the two runs is the shared box, not the index.
    • SQLite, with R4: SCAN bench_line_item USING INDEX tmp_bench_line_item_created.
    • PG, chained, after the index: Index Scan Backward using tmp_bench_line_item_created, with a nested-loop semi join over the two primary keys. Before the index: parallel hash semi join, then sort.

    Does R3's gain depend on R4? On SQLite yes, on PostgreSQL no.

    Corrected R3 expected-gain cell:

    index (created_at, id) at 1M. PG, independent of R4: admin default page as emitted today (chained) 229 -> 0.9 ms; member page 101 -> 3.2 ms; with R4 as well, 62 -> 0.5 ms. SQLite, depends on R4: the chained page keeps its chain-first plan, identical before and after the index: 1736 -> 1328 / 1320 -> 1391 ms over two runs; member page 163 -> 179 / 147 -> 145 ms. Only with the chain dropped (R4) does the page go 1707 -> 0.09 / 1183 -> 0.08 ms. The earlier "SQLite 1237 ms -> 0.09 ms" was R3 + R4 together.

    What this changes for M2:

    • On PostgreSQL, R3 can be filed and land on its own.
    • On SQLite, R3 alone buys nothing for these pages. Its gain arrives with R4, and R4 carries the orphan-semantics decision. File R3 with R4, or after it, if SQLite deployments are meant to benefit.
    • R12's "becomes the dominant cost once R3 lands" holds on PG. On SQLite it holds once R3 and R4 land.

    R1, which SQL shape produced the 0.14 s. It was sum(case when … end): micro.mjs I4 times that spelling on both dialects. PG now also times FILTER (WHERE …) (new row I4b), and the two match.

    Corrected R1 target cell:

    conditional aggregate in the GROUP BY, timed as sum(case when quantity >= 10 then quantity end) on both dialects. SQLite 5.13 s -> 0.54 s / 4.83 s -> 0.55 s (two runs); PG 4.39 s -> 0.144 s. PG FILTER (WHERE quantity >= 10) measures 0.145 s, the same within noise, so either spelling serves on PG. SQLite was not timed with FILTER. Earlier run: SQLite 5.10 -> 0.53 s, PG 5.09 -> 0.14 s. About 9x on SQLite and 30x–36x on PG.

    R5, the figure. At 100k the fixture holds 10,000 opportunities, so about 2,000 are won (the scenario's own note says ~2000). 20k is the 1M figure. Corrected R5 cost cell: "400 INVALID_FILTER already at 100k (~2,000 matching opportunities, past the 1000-id cap; ~20,000 at 1M)". The 400 verdict stands.

    The other rows of the 1M re-run agree with the original list within the box's run-to-run spread, and no other ranking changes. The full 1M tables for both dialects, each stamped with its commit and time, are in the follow-up comment on #33662.

  4. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · os-elon-musk · session_016WV4cztR1A2CZoxSZyuoGP

    M2 filing from the M0 ranked list (comment 6889544281, corrected 6889939163), 2026-11-15T06:42Z. Maintainer rulings on the seat's decision cards are quoted in each card.

    M0 item Card Area Ruling
    R2 lookup-dimension 500 past bind limit #33664 A3 defect, no ruling needed
    R3 + R11 implicit indexes created_at, owner_id #33695 A4 both (SQLite half Blocked-by #33696)
    R4 vacuous parent chain for unrestricted readers #33696 A2 + A4 drop only when the FK is required
    R5 cross-object filter semi-join #33626 (draft PR #33652) A3 memory keeps in-process; MongoDB/OData refuse 400 via ADR-0139 amendment
    R6 non-UTC bucketing on PostgreSQL #33697 A4 yes, amend ADR-0053 D2

    Not yet filed (waiting on the maintainer's pick): R1 per-measure filter aggregate, R7 cascade delete, R8 per-request identity reads, R9 sharing scope, R10 roll-up recompute, R12 paged count.

  5. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · os-elon-musk · session_016WV4cztR1A2CZoxSZyuoGP

    M2 filing, second batch (2026-11-15T06:45Z), on the maintainer's pick 「R1 R7 R12 各一张+测量卡」: R1 per-measure filter aggregate → #33698 (A4) · R7 cascade delete set-based → #33699 (A4 + A3) · R12 paged count → #33700 (E1 + UI, Blocked-by #33695) · R8/R9/R10 measurement → #33701 (A3). Every M0 item now has a card; with #33664 #33695 #33696 #33697 #33626 the epic holds 9 open children plus #33627 (skills).

  6. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · zhuangjianguo · session_01QsR2jRmmALkM1ftZxdVatQ

    SQL performance M0 addendum — R8, R9, R10 measured (#33701)

    Adds to the ranked list (comment 6889544281, corrected by 6889939163); both are left as they were. Bench legs: PR #33783, head ae8ecd623 (packages/qa/dogfood/bench/sql-perf, bench.mjs + micro.mjs; the README there documents --shares, --db-latency-ms, --grants-cache-ttl-ms, --sql-log). Every number below is from this card's own runs, window 2026-11-15T09:46Z to 2026-11-15T10:16Z, engine tree origin/main @ a557fa38 (the bench commits on top change no product code; each result file carries the bench commit it ran at: 45aa1a52, 1634e071 or 697ba8f9). SQLite: the better-sqlite3 SqlDriver. PostgreSQL 16: a private local cluster started for this card (fsync=off, synchronous_commit=off throughout, so write milliseconds are understated), stopped and removed afterwards. A shared 4-core box: statement counts are exact, milliseconds are indicative. p50 of 20 calls (10 at 1M), warmup 3.

    The maintainer picks what M2 files. Nothing here was filed. One reproduced defect (H2, under R9) is flagged for the seat to file.

    Ranked addendum

    # item measured cost (today) expected gain (target) pays? area size
    R10 Roll-up recompute: each recompute is 4 statements (select sum(f) / count(*) … where fk = ?, the parent read twice in full, one update parent set FIELD = ? …), one per summary field. createMany pays it per distinct parent per field; updateMany pays it per child row per field, because each row is its own engine update 50-row updateMany, 1 parent: 358 → 558 → 758 statements for 0 / 1 / 2 summary fields; SQLite 197 → 283 → 366 ms, PG 318 → 414 → 512 ms. 50-row createMany over 10 parents: 209 → 249 → 289 statements, +2 to +9 ms one grouped aggregate for every descriptor and parent (select fk, sum(f), count(*) … where fk in (…) group by fk) + one update per parent carrying all its fields, run once per batch: micro.mjs I10 (10 parents × 2 fields) 80 → 11 statements, SQLite 1.65 → 0.20 ms, PG 15.8 → 2.15 ms, same values. For updateMany the gain needs the recompute deferred to the end of the batch first yes — the largest multiplier measured here; over a network the 400 extra statements of a 2-summary 50-row update are about +1 s at 2.4 ms RTT and +4 s at 10.6 ms (statement count × the measured RTT; that write was not timed through the proxy) A4 (engine) M
    R9 Sharing read scope: the grants read (select record_id, access_level from sys_record_share where … order by id limit 5000) runs twice per member list (page and total; 5 times on a member record page) and binds every id into owner_id = ? or id in (…), also inside the controlled-by-parent chain 1M, 5000 grants, member account list: SQLite 19.9 → 39.5 ms, PG 20.9 → 50.3 ms (statements stay 14; the app side grows 11 → 17 ms SQLite, 8 → 22 ms PG). Past 5000 grants the extra grants are silently dropped (H2 below) or id in (select record_id from sys_record_share where object_name = ? and recipient_type = ? and recipient_id = ?), read once per statement: micro.mjs I9 at 1M / 5000 grants, same answers — account page + total + 2 grant reads SQLite 18.3 → 12.1 ms, PG 21.6 → 7.0 ms; line-item chain page PG 201 → 195 ms, total PG 99 → 86 ms (SQLite flat: 740 → 752, 60 → 58). It also answers every grant (7000 vs 6000 at 6000 grants) yes, defect first: the target shape is the fix for H2; the speed alone is modest on SQLite, about 3× on the PG scope statements A2 (plugin-sharing) S–M
    R8 Per-request identity: 8 statements warm on every request, admin and member alike (sys_session, sys_user ×2 — two callers read the same row by id —, sys_member ×2 incl. the organization's member list, permission sets, positions, metadata activation); a 10-statement list is 8 identity + 2 data locally 2–5 ms. Over the proxy (PG): public 1-row list 9.3 → 29.3 ms at 2 ms RTT, 75.7 ms at 10 ms; member list 36.2 → 64.4 / 144.8 ms; member record page (31 statements) 26.5 → 86.3 / 254.2 ms grants cache on (OS_AUTHZ_GRANTS_CACHE_TTL_MS=60000, shipped, default off by ruling): identity 8 → 2 statements (sys_session, sys_user); recovers 11 ms at 2 ms RTT and 19–25 ms at 10 ms; locally within noise. A request-scoped memo of the duplicate sys_user / sys_member reads is not measured as SQL only on a network database; turning the cache on is a deployment setting today, making it the default is a ruling question (Fork 4 of the grants-cache ruling), not an M2 code card A1 + A2 + core authz S (memo) / ruling (default)

    Rank by what pays: R10 first (largest statement multiplier, both dialects), R9 second (carries a defect; its target shape is also the fix), R8 third (pays only on a network database, and its cheapest lever already ships behind a setting).

    R8 over a network — method and readings

    Method: an in-process TCP proxy between the server and PostgreSQL that holds every chunk half the round trip in each direction (--db-latency-ms). Injected 2 ms: select 1 measured 0.1 ms direct, 2.4 / 2.5 ms through the proxy; injected 10 ms: 10.6 / 10.7 ms; each run forwarded 4,394 to 5,676 chunks to the database (fewer with the cache on). The grants cache's own boot line proves the cache posture of each run ([authz-cache] grants cache ENABLED (ttl=60000ms) with NO "authz.invalidated" invalidation bus …). 100k scale. p50 ms · statements:

    scenario RTT 0, cache off RTT 0, on 2 ms, off 2 ms, on 10 ms, off 10 ms, on
    public_list_tiny admin 9.3 · 10 8.2 · 4 29.3 · 10 18.1 · 4 75.7 · 10 56.8 · 4
    public_list_tiny member 9.5 · 10 7.0 · 4 28.3 · 10 18.0 · 4 77.0 · 10 54.9 · 4
    list_filter_sort admin 68.3 · 10 64.5 · 4 98.3 · 10 66.9 · 4 128.5 · 10 105.7 · 4
    list_filter_sort member 36.2 · 14 30.7 · 8 64.4 · 14 50.6 · 8 144.8 · 14 123.8 · 8
    scoped_account_list member 13.7 · 14 15.8 · 8 43.8 · 14 33.6 · 8 129.0 · 14 106.5 · 8
    record_page admin 21.1 · 18 23.2 · 12 56.8 · 18 43.8 · 12 150.6 · 18 126.0 · 12
    record_page member 26.5 · 31 31.7 · 25 86.3 · 31 73.9 · 25 254.2 · 31 228.8 · 25
    rollup0_insert_one admin 15.2 · 13 — 45.3 · 13 31.6 · 7 114.0 · 13 95.4 · 7
    rollup2_insert_one admin 17.9 · 21 — 67.3 · 21 58.1 · 15 206.7 · 21 189.5 · 15

    SQLite, local only (there is no connection to delay), cache off → on: public list admin 8.0 · 10 → 6.8 · 4, member 7.9 · 10 → 6.4 · 4; member list 19.7 · 14 → 19.7 · 8; member record page 26.1 · 31 → 28.6 · 25. The added latency is smaller than statements × RTT: part of the identity reads run concurrently.

    R9 — sharing scope, and H2

    Seeded as the sharing service stores a manual grant (sys_record_share, recipient_type = 'user'), on accounts the member does not own (--shares). Proof the leg exercises the scope: the member's account total equals owned + shared at 900 and 5000 grants, the largest statement of the member request carries 902 binds at 900 grants and 4 with none (both captured with --sql-log), and the shares-0 control reads only what it owns.

    scenario (member) SQLite 1M, 0 grants 5000 6000 PG 1M, 0 grants 5000 6000
    scoped_account_list (total) 19.9 ms (1000) 39.5 (6000) 42.2 (6000) 20.9 (1000) 50.3 (6000) 44.5 (6000)
    scoped_list_unfiltered (total) 159.8 (100000) 820.7 (600000) 832.1 (600000) 188.6 (100000) 295.8 (600000) 301.4 (600000)
    list_filter_sort 97.9 402.5 411.4 176.3 250.2 236.2

    Most of the growth is the member reading six times more rows, not the predicate's form. At 100k with 900 grants (the member then reads every account, the admin's set), member vs admin on the same rows: list SQLite 80.0 vs 73.7 ms, PG 75.1 vs 83.9; unfiltered list SQLite 153.1 vs 134.7, PG 97.8 vs 76.1.

    H2, reproduced on both dialects (class a, flagged for the seat to file). With 6000 grants the member sees 6000 accounts, not 7000 (1000 owned + 6000 shared): the read keeps the first 5000 grants by share id and drops the rest without a word. GET /data/bench_account/ac00009998 (granted; the 6000th grant) answers 404 RECORD_NOT_FOUND while GET /data/bench_account/ac00000001 (the first grant) answers 200; the member's line-item total is 600000 where the target shape answers 700000. Control at 5000 grants: 6000 / 6000 and both reads 200. Fail-closed (an under-grant, not a leak). Seam: SharingService#buildReadFilter, the sys_record_share read with limit: 5000 (plugin-sharing/src/sharing-service.ts, the grants read above grantedRecordIds). Dedupe words: sys_record_share limit 5000, grants past 5000 dropped, shared record 404 RECORD_NOT_FOUND, buildReadFilter grant cap.

    Not measured: hierarchy scopes (own_and_reports, unit* expand owner ids in the app), as the fixture has no hierarchy; grants through teams, roles or rules (only recipient_type = 'user' rows are read by this path).

    R10 — roll-up recompute

    Three fixed-size pairs, bench_roll0..2 (200 parents × 50 children), identical but for 0, 1 and 2 summary fields; the 0-field pair is the control. Statements are identical on both dialects:

    write (admin) 0 summaries 1 2 SQLite p50 ms (0 / 1 / 2) PG p50 ms (0 / 1 / 2)
    createMany 50 rows, 1 parent 209 213 217 157 / 145 / 148 190 / 167 / 187
    createMany 50 rows, 10 parents 209 249 289 172 / 170 / 174 195 / 198 / 204
    updateMany 50 rows, 1 parent 358 558 758 197 / 283 / 366 318 / 414 / 512
    updateMany 50 rows, 10 parents 358 558 758 229 / 289 / 359 283 / 330 / 458
    insert 1 row 13 17 21 12 / 16 / 14 15 / 16 / 18

    H3 holds for createMany (+4 statements per distinct parent per summary field) and understates updateMany: there the recompute runs once per child ROW per summary field, whatever the number of distinct parents (+200 statements per field for 50 rows). With two fields the same parent is also updated twice per recompute, one update per field.

    Not ranked (observed while capturing, no target measured)

    • A 50-row batch write is mostly per-row work even with no summary field: createMany reads the master twice per row (select id from parent where id = ?, with and without limit) and writes one sys_audit_log and one sys_activity row per row (209 statements); updateMany reads each child four times (358).
    • A member read of a private object also reads sys_queue (the queue-sitting match) once per statement it scopes: twice per list, five times on the record page.
    • The analytics member path ANDs the share-scoped chain twice (1802 binds at 900 grants), the same double chain R4 names for the admin.
  7. objectstack-fleet commented on Nov 18, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Regraded p1 → p2: p1 is now kept for queue jumps. The maintainer, in triage's session: 「以后我都会要求专门作有一个专题…p1 是不是应该留给真的需要插队的」. He then confirmed triage's review of every open p1 (「确认」). Development is dispatched by epic, and an epic orders its own work. p1 is kept for cards that must jump ahead of it: a regression users meet in a released version, a broken hosted first impression or core flow, data loss or a breach in normal use, or a release or customer blocker.

    Why this card: an epic: the maintainer orders epics himself, so an epic card needs no p1 to jump. Any claim on the card is unchanged.

  8. added
    priority:p2
    and removed
    priority:p1
    on Nov 18, 2026
  9. objectstack-fleet commented on Nov 19, 2026

    @objectstack-fleet
    ContributorAuthor

    qa#1 · os-justin · session_01QSeKYpxQpmErd1ixfkgbYh

    Milestone acceptance filed 2026-11-19T14:58Z: #35539. It re-tests 9 items at 92121196, with the live leg on SQLite and PostgreSQL 16: 7 PASS, 1 PARTIAL, 1 FAIL.

    Reading: the epic's promise holds on the SQL drivers measured.

    • A cross-object where compiles to one IN (SELECT … ) semi-join, with no id list and no 1,000 cap: 1,003 parents are served on both drivers, and 21,003 in 24 ms on PostgreSQL.
    • Each hop carries its own row scope, and an unreadable hop refuses or excludes rather than widens.
    • The orphan with a null parent is excluded under $ne.

    Other results:

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

    area:datadomain:serverpm:epicpriority:p2tracking

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions