FFFF Expression binding a variable a pattern also binds depends on plan order · Issue #596 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
10BC8

Expression binding a variable a pattern also binds depends on plan order #596

Closed

Description

@adityamukho

What happens

An expression binding ([(f …) ?x]) overwrites ?x at the point where optimizer::plan places it. When a pattern also binds ?x, the answer depends on whether that pattern runs before the expression or after it, so native (which reorders by selectivity) and --features wasm (which keeps source order) disagree:

(transact [[:a :age 30] [:b :age 40] [:p1 :score 41]])
(query [:find ?a ?x :where [?e :age ?a] [:p1 :score ?x] [(+ ?a 1) ?x]])
  • Native runs [:p1 :score ?x] first, then the expression overwrites ?x: [30 31] [40 41]. The score constraint is lost.
  • Wasm runs the expression first, then the pattern joins on it: [40 41].

Both the executor and the streaming engine do this; the engine reproduces the executor (decision 2 of the #545 plan).

Rule (settled with the maintainer, 2026-10-14)

Every plan must return the same rows the same number of times; only the order of rows may differ, and only when the query sets none.

An expression whose output variable is bound by another clause unifies: it keeps the rows where its result equals the bound value (standard Datalog), wherever it runs. So [(+ ?v 1) ?v] never matches, and two expressions binding the same variable must agree. This is a breaking change for v3.0.0: queries that relied on overwriting change (CHANGELOG, Breaking changes). Equality follows the join rules (#545): floats by IEEE ==, and a keyword equals a ref to the entity it names.

Also

A test that runs the engine's query matrix with reordering on and off in one build, and requires the same rows, so plan-dependent answers fail CI. Related: #594 (pseudo-attributes), #546 (substituted floats in not bodies).

Activity

  1. added this to the v3.0.0 milestone on Oct 14, 2026
  2. added
    bugSomething isn't working
    rustPull requests that update rust code
    on Oct 14, 2026
  3. added 2 commits that reference this issue on Oct 15, 2026
  4. adityamukho commented on Oct 15, 2026

    @adityamukho
    CollaboratorAuthor

    Fixed on v3 by #601 (3a5fdac): an expression binding a variable another clause binds now unifies (keeps the rows where the values are join-equal), on the executor, evaluator and streaming engine; the first binder in :where text gives the value. tests/plan_independence_test.rs checks a query matrix with reordering on and off. Docs: project-minigraf/minigraf-docs#18. Ships in v3.0.0.

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

    bugSomething isn't workingrustPull requests that update rust code

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0