Skip to content

Cypher WHERE (booleanVariable) is parsed as a single-node pattern and silently filters rows #9542

Closed

Description

@shulei5831sl

ArcadeDB version

  • Image: arcadedata/arcadedb:latest
  • Version: 26.11.1-SNAPSHOT
  • Build: 31930bb8bb9f295331db42c3d42ca61f7f4a65dc
  • Tested: 2026-10-09
  • Query language: Cypher / OpenCypher

Description

ArcadeDB silently drops rows when a Boolean variable is enclosed in parentheses in a WHERE clause following WITH.

The query below should return one row because flag is bound to true. Instead, it returns an empty result.

Removing the parentheses restores the expected behavior.

The issue appears to be in Boolean predicate parsing rather than Boolean comparison or evaluation. A parenthesized variable appears to be interpreted as a single-node graph pattern instead of a Boolean expression.

Steps to reproduce

No graph setup is required.

WITH true AS flag
WHERE (flag)
RETURN flag;

Expected result:

flag = true

Actual result:

[]

The query succeeds without an error or warning.

Control: Boolean comparison works without parentheses

The same behavior can be demonstrated using a comparison result stored in a variable.

WITH 3.14 AS lhs, 1 AS rhs
WITH lhs, rhs, lhs > rhs AS result
WHERE result
RETURN lhs, rhs;

Actual result (correct):

lhs = 3.14
rhs = 1

Adding parentheses around the Boolean variable:

WITH 3.14 AS lhs, 1 AS rhs
WITH lhs, rhs, lhs > rhs AS result
WHERE (result)
RETURN lhs, rhs;

Actual result (incorrect):

[]

The comparison itself also works:

RETURN 3.14 > 1 AS result;

Actual:

result = true

These controls isolate the failure to the parenthesized Boolean variable in WHERE, not to numeric comparison.

Probable cause

In CypherASTBuilder.parseBooleanFromExpression7(), the parenthesized-expression handling checks whether the inner text is a bare identifier and excludes only the Boolean and null keywords.

See CypherASTBuilder.java, lines 1447–1464.

A parenthesized identifier such as (flag) therefore appears to enter the single-node-pattern branch, even when flag is a Boolean variable introduced by WITH.

The resulting PatternPredicateExpression returns false for a pattern containing no relationships.

See PatternPredicateExpression.java, lines 76–83.

This explains the observed silent row filtering. The precise execution path has not been instrumented, but the source behavior is consistent with the reproduction.

Relationship to #8994

This appears to be a remaining case from #8994, which reported that parenthesized Boolean literals such as WHERE (true) were incorrectly treated as node patterns.

PR #9158 fixed that issue by distinguishing the Boolean and null keywords from ordinary identifiers.

However, a Boolean variable such as (flag) still takes the problematic identifier path in the tested latest snapshot.

The earlier fix covers parenthesized literals, while this report demonstrates that parenthesized Boolean variables remain affected.

Impact

Queries using computed or aliased Boolean predicates can silently return no rows when a redundant pair of parentheses is added.

For example, a predicate computed by WITH can produce different results solely because it is written as WHERE (result) rather than WHERE result.

Since the query succeeds without an error, applications may interpret the empty result as a legitimate absence of matching data.

Workaround: Remove the parentheses around the Boolean variable in the WHERE clause.

Activity

  1. added
    engine
    severity:minor
    on Oct 9, 2026
  2. added this to the 26.11.1 milestone on Oct 9, 2026
  3. added
    in progress
    on Oct 9, 2026
  4. self-assigned this
    on Oct 9, 2026
  5. added 4 commits that reference this issue on Oct 9, 2026
  6. lvca commented on Oct 9, 2026

    @lvca
    Member

    Fixed in #9588 (26.11.1).

    WHERE (flag) was always read as a node pattern, so it dropped every row. A parenthesized variable is now treated as a value: a Boolean works like WHERE flag, null is unknown, and anything that is not a Boolean (for example a node or a number) raises an InvalidArgumentType error instead of silently returning nothing.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Oct 9, 2026
  8. added a commit that references this issue on Oct 11, 2026
  9. added 4 commits that reference this issue on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugengineopencypherseverity:minor

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions