Repository navigation
Description
ArcadeDB version
arcadedata/arcadedb:latest
ArcadeDB version: 26.7.2-SNAPSHOT
Environment
- Host OS: Linux
- Deployment: Docker
- Query interface: HTTP
/api/v1/command/test - Query language: Cypher
- Differential comparison: Neo4j 2026.05.0
Description
A correlated count { ... } expression subquery returns incorrect counts when the subquery contains a WHERE predicate combining IS NULL with another predicate using OR.
Simple predicates are counted correctly, and IS NULL alone is also counted correctly. The wrong result appears when the predicates are combined as:
WHERE f.active IS NULL OR f.active = trueSteps to reproduce
Run from a clean database.
MATCH (n) DETACH DELETE n;
CREATE
(u1:User {id:1, active:true}),
(u2:User {id:2, active:true}),
(u3:User {id:3, active:true}),
(u4:User {id:4, active:false}),
(u5:User {id:5, active:false}),
(u6:User {id:6, active:false}),
(u1)-[:FRIEND]->(u4),
(u1)-[:FRIEND]->(u5),
(u2)-[:FRIEND]->(u4),
(u2)-[:FRIEND]->(u1),
(u3)-[:FRIEND]->(u5),
(u3)-[:FRIEND]->(u6);Data summary:
u1 -> u4(false), u5(false)
u2 -> u4(false), u1(true)
u3 -> u5(false), u6(false)
No matched friend has active IS NULL. Only u2 has a friend with active = true.
Failing query
MATCH (u:User {active:true})
RETURN u.id,
count {
MATCH (u)-[:FRIEND]->(f:User)
WHERE f.active IS NULL OR f.active = true
} AS cnt
ORDER BY u.id;Expected behavior
Only u2 should have one matching friend.
u.id | cnt
-----+----
1 | 0
2 | 1
3 | 0
Neo4j 2026.05.0 returns:
1 | 0
2 | 1
3 | 0
Actual behavior
ArcadeDB returns:
u.id | cnt
-----+----
1 | 1
2 | 1
3 | 1
Rows u1 and u3 are false positives: both only have friends with active:false, so the count should be 0.
Control queries
The same count {} expression works correctly without OR.
MATCH (u:User {active:true})
RETURN u.id,
count {
MATCH (u)-[:FRIEND]->(f:User)
WHERE f.active = true
} AS cnt
ORDER BY u.id;Expected and observed on ArcadeDB:
1 | 0
2 | 1
3 | 0
IS NULL alone is also correct:
MATCH (u:User {active:true})
RETURN u.id,
count {
MATCH (u)-[:FRIEND]->(f:User)
WHERE f.active IS NULL
} AS cnt
ORDER BY u.id;Expected and observed on ArcadeDB:
1 | 0
2 | 0
3 | 0
A basic correlated count {} without WHERE is also correct:
MATCH (u:User {active:true})
RETURN u.id,
count {
MATCH (u)-[:FRIEND]->(:User)
} AS cnt
ORDER BY u.id;Expected and observed on ArcadeDB:
1 | 2
2 | 2
3 | 2
Additional control: equivalent aggregation outside count{}
The equivalent aggregation outside the count {} expression should return the expected result:
MATCH (u:User {active:true})
MATCH (u)-[:FRIEND]->(f:User)
WITH u.id AS id,
sum(CASE WHEN f.active IS NULL OR f.active = true THEN 1 ELSE 0 END) AS cnt
RETURN id, cnt
ORDER BY id;Expected:
1 | 0
2 | 1
3 | 0
Cross-engine comparison
Failing query:
MATCH (u:User {active:true})
RETURN u.id,
count {
MATCH (u)-[:FRIEND]->(f:User)
WHERE f.active IS NULL OR f.active = true
} AS cnt
ORDER BY u.id;| Engine | u1 | u2 | u3 |
|---|---|---|---|
| Neo4j 2026.05.0 | 0 | 1 | 0 |
| ArcadeDB 26.7.2-SNAPSHOT | 1 | 1 | 1 |
Summary
The correlated count {} expression appears to mis-handle a WHERE predicate containing IS NULL OR .... The result is a false-positive count of 1 for outer rows where the subquery should count zero matching rows.
Activity
fix(#5165): parenthesize inner WHERE in correlated count{} subquery
Merge fix(#5165): parenthesize inner WHERE in correlated count{} subq…
lvca commentedon Jul 9, 2026
Confirmed and fixed in main (will ship in the next release).
What happened: in a correlated
count { ... }subquery, ArcadeDB injects a hidden filter to tie the inner match to the current outer row. When your innerWHEREusedOR(e.g.f.active IS NULL OR f.active = true), that hidden filter was combined with a bareAND, and becauseANDbinds tighter thanORthe condition effectively became(row-link AND f.active IS NULL) OR f.active = true. TheORbranch then matched globally instead of per row, which is why every user got a count of 1.Fix: the inner
WHEREis now wrapped in parentheses before the row-link is added, soORkeeps its intended meaning. Your query now returns0 / 1 / 0as expected, matching Neo4j.Thanks for the very clear report and the ready-made reproduction, it made this quick to pin down.
fix(engine) #5656: a Cypher subquery body is part of the query, not a…
fix(engine) #5656: a Cypher subquery body is part of the query, not a…
fix(#5165): parenthesize inner WHERE in correlated count{} subquery
fix(engine) #5656: a Cypher subquery body is part of the query, not a…