Skip to content

perf(read): within_groups scans the full active match_scores per request — measure before it matters #833

Done

Description

@athvin

The observation

entities/match_score/read/within_groups.sql (shipped in #797's PR) restricts its members CTE to the page's entity-id range but names the entire active match_scores relation in the scored CTE — the page bound arrives only through the hash join. Per /duplicates or /merge-plans request that's O(active match_scores) rows read to return ≤ ~10³ within-group edges; at tenant scale that relation is 10⁵–10⁷ rows.

Found by the /pr-review tier reviewer on PR #827, which declined it as a finding per the measurement rules: the identical per-request full active-scan shape already exists in uncertain_page.sql and active_page.sql, and a performance claim needs the experiment matrix, not a read of the SQL.

Done when (per ducklake-performance)

  • a measurement of the per-request rows-read for /duplicates and /merge-plans at a stated corpus size, against the same endpoints before the statement existed (is there a regression at all?)
  • if it bites: candidates are restricting scored through the members CTE earlier, a covering sort-on-write, or accepting it — each with its own measurement
  • the verdict recorded in the statement's yaml description

Priority note: the read API's established posture is a bounded envelope rather than a bounded scan, so this may legitimately close as measured-and-fine.


Product context (2026-11-26)

Why this matters for the API product: /duplicates and /merge-plans are results endpoints in the public contract (rust/crates/er-server/src/lib.rs:15013, 15193). Each page read scans all active match_scores, so latency grows with the tenant's corpus instead of the page size.

Current state:

  • entities/match_score/read/within_groups.sql is unchanged since feat(ui): group search by member id, and the seven missing group filters (#801) #854 (b3e35e4). The scored CTE still reads every is_active row, and the page bound arrives only through the join.
  • The caller is edges_by_entity in rust/crates/er-server/src/read.rs:651. The assertion arm (read.rs:671) has the same shape, but its relation is far smaller.
  • No measurement has been recorded, and the yaml description carries no verdict.

Definition of done: As above. Also state the corpus size and the p50/p95 latency per page, not just the rows read, because latency is what an API customer sees.

Dependencies / sequencing: It needs a large lake. #558's 10M corpus is the obvious one, and a 1M lake would give a first answer. Run the same measurement on uncertain_page.sql and active_page.sql too, since they share the shape. Related: #529 (public duplicate-check API) reads the same relations.

Size: About 0.5 engineer-weeks to measure. Add 0.5 if a rewrite is justified.

Activity

  1. added
    followup
    on Nov 8, 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

    followup

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions