Skip to content

[Decision] Analytics cross-object filters beyond one hop: how many hops, and on which mechanism (staged id reads vs a subquery leaf)? #33619

Closed as not planned

Description

@objectstack-fleet

triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

Filing gate: ② a decision only the maintainer can make. Filed on the maintainer's direct word, verbatim, in the triage seat session on 2026-11-15: 「上限 5 层,按照我们的设计会导致性能问题嘛?这个开发复杂吗?风险大吗?用fable综合评估,立决策卡」. The assessment below is a Fable evaluation that read main c32bb6cc and PR #33512's head 1e79a28d. It is read from code; no benchmark was run. Performance statements are inferred from the code's structure.

Follow-up of #33335 (PR #33512, one hop, in the merge queue). The pull is the downstream carbon-black CRM (steedos-labs/os-project-blackcat-crm#119): its margin dashboard must leave out rows whose order is cancelled, and its allocation-by-plant tile reads plan lines, so the path is plan line → plan → order (two hops).

维护者速读

  • 结论:真正卡住下游的不是层数,是引擎对跨对象过滤的 1000 个 id 上限。今天的做法是先查出满足条件的父记录 id,再用 IN 过滤。「订单状态 ≠ 已取消」匹配的几乎是全部订单,订单超过 1000 张时,一层也会返回 400。PR feat(service-analytics): serve a one-hop cross-object where on the engine-aggregate path #33512 拒绝了否定写法,因为否定会放行父记录不可读的行。把同一机制叠到 5 层,只会把问题放大。
  • 建议:先合 feat(service-analytics): serve a one-hop cross-object where on the engine-aggregate path #33512(一层,写明上限),再做 C:复用仓库已有的子查询组合机制(ADR-0139 ReadableIds),上限 3 层。SQL、Turso、内存驱动没有 id 上限,可用于百万行。其他驱动响亮拒绝。约 8–12 agent-day,需一份 ADR,安全评审是重点。
  • 不建议 5 层:数据集编译器和 ADR-0071 已定默认最多 3 跳,数据集今天声明不出 4–5 跳的关联。对齐 Salesforce 的 5 级应作为单独的 ADR 修订,C 落地后再议。
  • 急用:B(沿用现有做法递归到 3 层,每层 1000 上限)约 3–4 天,安全风险低,但「≠ 已取消」这类过滤在真实数据量下仍会 400。只适合作过渡。

What the engine does today (read from code)

  • A nested-relation condition is a two-step semi-join, not a driver join: lowerRelationConditions (packages/objectql/src/engine-query-lowering.ts:181-217) runs the engine's own find(target, { where, fields: ['id'], limit: CAP+1 }) under the caller's context, then rewrites to $in.
  • RELATION_FILTER_ID_CAP = 1000 (relation-filter-lowering.ts:84). Over the cap it answers INVALID_FILTER 400 and never truncates (engine-query-lowering.ts:205-207).
  • One level only: a second level is refused (relation-filter-lowering.ts:186-196). Each condition costs one extra serial round trip.
  • Raising the cap is not viable. Each id is a bind parameter, and ADR-0139 moved to subqueries exactly because id lists hit dialect bind limits (native-sql-strategy.ts:856-862).
  • The repo already has an uncapped, security-reviewed mechanism: ADR-0139's ReadableIds leaf. driver-sql compiles it to a nestable field IN (SELECT id FROM P WHERE scope AND tenant) (sql-driver.ts:6371-6385), with a chain-depth cap of 8 (engine-readable-ids-permission-formula.ts:117). Memory rewrites it to an id list, and Turso has its own semi-join. Mongo and OData are not supported (core/src/utils/readable-ids-driver-refusal.ts:126-127,181).
  • NativeSQLStrategy already does any number of hops as LEFT JOINs (ADR-0071), but it declines many shapes: time buckets, federated objects, engine middleware, controlled_by_parent read scopes, and others.

Options

Shape Cost Risk What the downstream app gets
A Stop at one hop (#33512) and document the 1000-parent cap 0 none new Small or selective filters only. A "matching parents > 1000 → 400" note in the docs
B Staged recursion to 3 hops, cap 1000 per hop, loud refusal naming the hop M, ~3–4 agent-days low (every hop is find as the caller: one CRUD/row/field gate) Plan line → plan → order, but only while every hop's id set is small. != cancelled still 400s at real volume
C A subquery leaf: extend ADR-0139's composed leaf to carry a condition. 3 hops; SQL/Turso/memory uncapped; other drivers fall back to B and refuse loudly L, ~8–12 agent-days + an ADR higher: composeReadableIds asks only canReadObject / getReadFilter, so the filter-oracle check on the condition field must be added explicitly, or existence leaks A filter that works at 1M rows, and the one-hop cliff in A goes away
D Native SQL only: widen NativeSQLStrategy.canHandle XL (each shape is its own project, which duplicates engine composition in native, against the #7598 ruling) high Nothing on memory or mongo

5 hops under any option needs an ADR-0071 amendment, a compiler constant change (MAX_JOIN_HOPS = 3, dataset-compiler.ts:625,806-814), lint text (rule-explanations.ts:638), docs (dataset.mdx:62, query-syntax.mdx:519) and the objectui field picker: another M on top.

Risks common to B and C

  • Divergence between strategies. ObjectQL says a missing or unreadable parent never matches, $ne included. Native is LEFT JOIN + WHERE, and its NULL handling depends on how $ne lowers. This was not verified case by case, so a native-vs-ObjectQL parity matrix is required.
  • controlled_by_parent and tenancy. Under B, each hop's find composes the scope and the wall. Under C, ADR-0139 D5 refuses parents with object read middleware or a cross-datasource parent, so those must fall back to B.
  • Performance cliff. Under A and B, a dashboard goes from working to 400 as data grows. That is better than silent truncation, but downstream it is still an outage.
  • Not covered by feat(service-analytics): serve a one-hop cross-object where on the engine-aggregate path #33512. A dataset's own filter and per-measure filters still refuse cross-object leaves on the ObjectQL path (PR tests crossobject-conjunct-refusal.test.ts:517,637,758).
  • Breaking: none in any option. Each one turns a refusal into a served answer.

Four-dimension analysis

Recommendation

A now (land #33512 with the cap documented), then C capped at 3 hops. No 5 hops now, no D. If the downstream needs two hops before C lands, B as a bridge: its engine change (lift second-level, add a depth counter) is reusable in C, but the error text and docs must state the cap.

Reader who acts on the ruling: domain:server (A3 analytics, with the objectql engine; E2 holds objectql function holders). Under the pilot, domain:server#5 assigns. ⛔ Not a claim.

Activity

  1. added
    priority:p2
    needs-user-decision
    domain:server
    on Nov 15, 2026
  2. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Ruling: #33619 · letter A · maintainer 「同意一层」 · 2026-11-15T03:05Z

    Ruled in the triage seat's session on 2026-11-15.

    Blocked-by: #33512 (PR)

  3. added
    pm:blocked
    and removed
    needs-user-decision
    priority:p2
    on Nov 15, 2026
  4. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Maintainer principle, 2026-11-15 · it amends the direction after one hop · 2026-11-15T03:18Z

    Verbatim, in the triage seat session: 「有的功能如果Mongo内存不支持,那就不需要支持,首先保sql,应该用最高性能的方案,而不能为了兼容而兼容」, after 「我的意见是一层先落地」.

    • Unchanged: one hop lands first (PR feat(service-analytics): serve a one-hop cross-object where on the engine-aggregate path #33512, ruling A above), and this card still owes the docs and refusal copy.
    • Changed for what follows: the Fable assessment's fallback, "other drivers fall back to staged id reads (B)", is dropped. The next step is SQL-first: on SQL drivers (driver-sql dialects, Turso), compile a cross-object where into an in-database semi-join (IN (SELECT …), each hop carrying that object's read scope, the ADR-0139 composition) with no 1000-id cap. Drivers that cannot run it (memory, mongo, OData) refuse loudly. They are not served by a slower path kept only for parity. This agrees with the standing freeze on driver-memory and driver-mongodb, [裁决] driver-memory / driver-mongodb 投入冻结 —— 维护者 2026-08-05 口径(跨单锚点) #5499 (2026-08-05).
    • That work is a new card (linked below), so this card stays the docs and copy item for one hop. The hop count beyond ADR-0071's 3 (the 5-level question) stays separate. It needs an ADR-0071 amendment once the SQL path exists.
  5. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Triage: unblocked · pm:blocked → pm:queue · 2026-11-15T03:50Z

    ⛔ Not a claim.

    PR #33512 merged, so the one-hop docs and refusal copy this card carries (ruling A) can land: the one-hop limit and the 1000-parent cap stated, with the refusal pointing to the native SQL strategy. p3 · A3. The uncapped follow-up is #33626.

  6. added
    pm:queue
    and removed
    pm:blocked
    on Nov 15, 2026
  7. os-bob commented on Nov 18, 2026

    @os-bob
    Contributor

    A downstream consumer case for this decision, on 18.5.0.

    steedos-labs/os-project-blackcat-crm has a dashboard tile, "Allocation by Plant", built on a dataset over allocation lines. To leave out lines whose order is cancelled, it needs the two-hop path allocation_plan.cb_order.status: line → plan → order. #33512 serves one hop, so the app can now fix its plan-level tiles (cb_order.status on the plan dataset). The line-level tile still gets 400 INVALID_FIELD and keeps counting cancelled orders.

    The app will not copy the order status onto lines while this decision is open, so that half of its card is held on this issue. Two hops (detail → header → order) is the depth this consumer needs.


    Generated by Claude Code

  8. objectstack-fleet commented on Nov 20, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#7 · os-tesla · session_01L9qibvvVzM5KhCWkT5f45c

    Closing as superseded at 2026-11-20T09:19Z. The maintainer (Tesla) picked 「关闭,已被取代」 on seat 7's decision card (2026-11-20T09:18Z).

    The pull behind this card was the 1,000-id cap on staged cross-object reads, not the hop count. Two later changes overtook ruling A (6888364691, one hop): the SQL-first principle (6888468549), and #33652's uncapped semi-join for single-valued relation conditions. main now serves three hops, and content/docs (query syntax) documents the limits. The tenancy-class case that still keeps the cap is #34157's; it is not reopened here.

  9. removed
    pm:queue
    on Nov 20, 2026
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:serverpriority:p3

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions