Skip to content

Commit 251ac43

Browse files
galdretonsky
authored andcommitted
Fix bug with or/or-join when shortcircuiting resolve-clause
1 parent 658390a commit 251ac43

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/datascript/query.cljc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@
133133
(= attrs-a attrs-b)
134134
(Relation. attrs-a (into (vec tuples-a) tuples-b))
135135

136-
(not (same-keys? attrs-a attrs-b))
136+
(and (not (same-keys? attrs-a attrs-b))
137+
(seq tuples-a) ; could be empty because
138+
(seq tuples-b)) ; a query short-circuited
137139
(raise "Can’t sum relations with different attrs: " attrs-a " and " attrs-b
138140
{:error :query/where})
139141

test/datascript/test/query_or.cljc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,23 @@
8181
(or-join [?e]
8282
(and [?e :age ?a]
8383
[?e2 :age ?a]))]
84-
#{1 2 3 4 5 6})
84+
#{1 2 3 4 5 6}
85+
86+
[(or-join [?e ?n]
87+
(and [?e :age 30] ; no matches, so this branch short-circuits
88+
[?e :name ?n])
89+
(and [?e :age 20]
90+
[?e :name ?n]))
91+
[(ground "Ivan") ?n]]
92+
#{2 6}
93+
94+
[(or
95+
(and [?e :age 30] ; no matches, so this branch short-circuits
96+
[?e :name ?n])
97+
(and [?e :age 20]
98+
[?e :name ?n]))
99+
[(ground "Ivan") ?n]]
100+
#{2 6})
85101

86102
;; #348
87103
(is (= #{[1] [3] [4] [5]}
@@ -184,4 +200,4 @@
184200
(d/q '[:find ?e
185201
:where (or-join [[?e]]
186202
[?e :name "Ivan"])]
187-
@test-db))))
203+
@test-db))))

0 commit comments

Comments
 (0)