Skip to content

EXISTS {} subquery with AND NOT EXISTS gives wrong result in ArcadeDB #4995

Closed

Description

@shulei5831sl

ArcadeDB version

  • Docker image: arcadedata/arcadedb:latest
  • Observed version: 26.7.2-SNAPSHOT
  • Build: 614f684589176b391059c9a985fbe99d34891628/1783267915250/main
  • Retested on: 2026-07-06
  • Endpoint: HTTP /api/v1/command/test
  • Language: opencypher

Description

A correlated EXISTS { ... } predicate combined with AND NOT EXISTS { ... } drops a row that should match.

In the reproducer below, user 1 is active, has one outgoing FRIEND relationship, and that friend has active = false. Therefore user 1 satisfies both predicates:

  • EXISTS { MATCH (u)-[:FRIEND]->(:User) }
  • NOT EXISTS { MATCH (u)-[:FRIEND]->(f:User) WHERE f.active IS NULL OR f.active = true }

However, ArcadeDB does not update the matching user. The query completes without error, but no row is written.

The semantically equivalent control query using OPTIONAL MATCH, collect(), and all() works correctly on the same graph.

Reproduce

Please run from a clean database.

If using HTTP /api/v1/command/test, submit each statement separately, but keep the CREATE statement below as one command so the variables remain in scope.

MATCH (n) DETACH DELETE n;
CREATE
  (u1:User {id: 1, active: true}),
  (u2:User {id: 2, active: false}),
  (u3:User {id: 3, active: true}),
  (u1)-[:FRIEND]->(u2),
  (u3)-[:FRIEND]->(u1);

Failing query:

MATCH (u:User {active: true})
WHERE EXISTS {
    MATCH (u)-[:FRIEND]->(:User)
  }
  AND NOT EXISTS {
    MATCH (u)-[:FRIEND]->(f:User)
    WHERE f.active IS NULL OR f.active = true
  }
SET u.flagged = true;

Readback:

MATCH (u:User)
WHERE u.flagged = true
RETURN u.id AS uid
ORDER BY uid;

Expected behavior

uid = 1

Only user 1 should be flagged:

  • u1 is active.
  • u1 has one outgoing FRIEND.
  • u1's only friend is u2, where u2.active = false.
  • Therefore the positive EXISTS predicate is true.
  • The negative NOT EXISTS predicate is also true, because there is no friend of u1 with active IS NULL or active = true.

User 3 should not be flagged, because u3 has friend u1, and u1.active = true.

Actual behavior

Observed on arcadedata/arcadedb:latest, version 26.7.2-SNAPSHOT, build 614f684589176b391059c9a985fbe99d34891628/1783267915250/main:

(empty result)

No user is flagged.

Control: equivalent query works

Please run from a clean database.

MATCH (n) DETACH DELETE n;
CREATE
  (u1:User {id: 1, active: true}),
  (u2:User {id: 2, active: false}),
  (u3:User {id: 3, active: true}),
  (u1)-[:FRIEND]->(u2),
  (u3)-[:FRIEND]->(u1);

Equivalent query without correlated EXISTS / NOT EXISTS composition:

MATCH (u:User {active: true})
OPTIONAL MATCH (u)-[:FRIEND]->(f:User)
WITH u, collect(f) AS friends
WHERE size(friends) > 0
  AND all(x IN friends WHERE x.active = false)
SET u.flagged = true;

Readback:

MATCH (u:User)
WHERE u.flagged = true
RETURN u.id AS uid
ORDER BY uid;

Observed on the same ArcadeDB build:

uid = 1

Why this looks like a bug

  • The graph contains a matching user.
  • The failing query is accepted and completes without error.
  • No user is updated, even though user 1 satisfies both predicates.
  • The equivalent OPTIONAL MATCH + collect() + all() formulation updates user 1 correctly.
  • The issue is not caused by missing data, write failure, or readback failure.
  • The failure appears specific to composing a correlated positive EXISTS { ... } predicate with a correlated AND NOT EXISTS { ... } predicate.

Activity

  1. shulei5831sl commented on Jul 5, 2026

    @shulei5831sl
    Author

    I updated the issue description with a smaller deterministic reproducer and retested it on the current arcadedata/arcadedb:latest image.

    Retested environment:

    • Version: 26.7.2-SNAPSHOT
    • Build: 614f684589176b391059c9a985fbe99d34891628/1783267915250/main
    • Endpoint: HTTP /api/v1/command/test
    • Language: opencypher

    The new reproducer removes the random-seed graph and keeps only the minimal case: one active user with one inactive friend.

    The failure is still:

    • Expected flagged user: uid = 1
    • Actual result: empty result

    The equivalent OPTIONAL MATCH + collect() + all() control query still returns uid = 1 on the same build.

    So the issue appears to be deterministic and specific to the composition of correlated EXISTS { ... } with correlated AND NOT EXISTS { ... }, rather than random seed initialization.

  2. self-assigned this
    on Jul 5, 2026
  3. added theissue type on Jul 5, 2026
  4. added this to the 26.7.2 milestone on Jul 5, 2026
  5. added a commit that references this issue on Jul 5, 2026
  6. lvca commented on Jul 5, 2026

    @lvca
    Member

    Fixed in main (commit 535e261), will ship in the next release.

    What was happening: when a correlated EXISTS { ... } / NOT EXISTS { ... } subquery had a WHERE with a top-level OR (like WHERE f.active IS NULL OR f.active = true), the engine linked the outer correlation to only the first side of the OR, because AND binds tighter than OR. As a result the subquery matched unrelated users and dropped rows that should have matched.

    Your reproducer now correctly flags uid = 1. Thanks for the clear, deterministic report.

  7. added 2 commits that reference this issue on Aug 1, 2026
  8. added 2 commits that reference this issue on Aug 14, 2026
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

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions