FalkorDB / FalkorDB

A super fast Graph Database uses GraphBLAS under the hood for its sparse adjacency matrix graph representation. Our goal is to provide the best Knowledge Graph for LLM (GraphRAG).

Home Page:https://www.falkordb.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected result about OPTIONAL

swilly22 opened this issue · comments

Ref: RedisGraph/RedisGraph#3219

I execute two queries on my RedisGraph and get an error.

Redis version:7.2.0
RedisGraph version: v2.12.10
operating system: windows 11
API:Cypher version 9

To create graph:
CREATE ()<-[:T]-()-[:T]->(),()<-[:T]-()

Query pair:
Ⅰ: OPTIONAL MATCH (n0)<-[]-(n1)-[]->(n2) RETURN count(1)
Ⅱ: MATCH (n0)<-[]-(n1)-[]->(n2) RETURN count(1)

I think these two queries should both return 2, but the first returns 5.

Refining the CREATE pattern for ilustration purposes:

CREATE ({v:1})<-[:T]-({v:2})-[:T]->({v:3}),({v:4})<-[:T]-({v:5})

In the graph created above, only 2 nodes (({v:1}) and ({v:3})) satisfies the MATCH pattern.
This is why the query:

MATCH (n0)<-[]-(n1)-[]->(n2) RETURN count(1)

Returns 2.

When specifying OPTIONAL for a MATCH pattern the query continues to execute even if the specified pattern did not matched.
This is the reason why the query:

OPTIONAL MATCH (n0)<-[]-(n1)-[]->(n2) RETURN count(1)

Returns 5.
The nodes (({v:2}), ({v:4}) and ({v:5})) did not satisfied the pattern but because of OPTIONAL the query continued executing reaching the aggregation part for all 5 nodes.