8000 An or branch holding only an expression over outer variables never matches · Issue #620 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

An or branch holding only an expression over outer variables never matches #620

Closed

Description

@adityamukho

Summary

An or / or-and branch whose expression clause reads a variable bound outside the or never matches, so the or drops rows it should keep. No error is raised.

Reproduction (v3 36d547ae, and main v2.0.7 228a0870)

(transact [[:a :n 1] [:b :n 2]])
(query [:find ?v :where [?e :n ?v] (or [(> ?v 1)] [(< ?v 0)])])
;; No results  (expected: 2)
(query [:find ?w :where [?e :n ?v] (or (and [(= ?v 1)] [?e :n ?w]) (and [(= ?v 2)] [?e :n ?w]))])
;; No results  (expected: 1, 2)
(query [:find ?v :where [?e :n ?v] [(> ?v 1)]])
;; 2           (correct without the or)
(query [:find ?v :where [?e :n ?v] (or (and [?e :n ?v] [(> ?v 1)]) [?e :n 5])])
;; 2           (works when the branch re-binds ?v itself)

The same happens in rule bodies (found while writing tests for #617 / PR #619).

Cause

apply_or_clauses (src/query/datalog/executor.rs), when no branch has not / not-join or reads metadata, evaluates each branch on its own from a single empty binding and joins the result with the incoming rows afterwards. evaluate_branch then applies the branch's expressions to rows where the outer variable is unbound, so the expression fails and the branch yields nothing. The seeded path (each incoming row seeds each branch), used when a branch has not / not-join, does not have this problem.

Fix direction

Use the seeded evaluation (or seed with the incoming bindings' values of the variables the branch reads) when a branch has an expression clause that reads a variable the branch's own patterns do not bind — as is already done for not / not-join and pseudo-attributes. Regression tests: the queries above, in a query and in a rule body, with the reorder switch on and off (tests/plan_independence_test.rs).

Related: #610 (an or sharing no variable with earlier clauses), #546 (or in the streaming engine).

Activity

  1. added this to the v3.0.0 milestone on Oct 16, 2026
  2. added
    bugSomething isn't working
    known-issueBug present in a published release and not yet fixed in one; listed in the pinned known-issues issue
    on Oct 16, 2026
  3. adityamukho commented on Oct 18, 2026

    @adityamukho
    CollaboratorAuthor

    Also affects or-join: (query [:find ?v :where [?e :n ?v] (or-join [?v] [(> ?v 1)] [(< ?v 0)])]) returns no rows (expected 2), from the same empty-seed path. Covered by the v3 fix.

  4. adityamukho commented on Oct 20, 2026

    @adityamukho
    CollaboratorAuthor

    Released in v2.0.8 (crates.io 2.0.8, 2026-10-20); also fixed on v3 for v3.0.0. Moved to "Fixed in v2.0.8" in #421.

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 workingdata-integrityData integrity issueknown-issueBug present in a published release and not yet fixed in one; listed in the pinned known-issues issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0