Skip to content

feat Cross-scope correlation in existence tests (deferred from ADR-0007) #309

Description

@0x054

Deferred by owner decision during the #307/#308 design session (2026-07-18). See ADR-0007 (docs/adr/0007-reverse-relations-tested-not-traversed.md) and the design spec (docs/plans/2026-07-18-016-existence-tests-design.md).

What is deferred

An existence test's inner lambda referencing any scope other than its own parameter — closing over the outer proxy for a correlated column-to-column comparison:

Txn.where(lambda t: t.lines.exists(lambda l: l.amount_minor == t.amount_minor))

SQL-wise this is legal (the subquery is already correlated), but it is rejected at build time in v1 with a clear error.

Why deferred

Acceptance shape (when picked up)

  • Owner-scope marker on leaf IR (backward-compatible addition), outer-alias qualification in the EXISTS render path.
  • Column-to-column comparison as a first-class predicate (likely its own design pass — it is meaningful outside subqueries too).
  • The v1 build-time rejection message updated to point here until shipped.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions