MATCH does not enforce implicit distinctness between differently-named node variables bound to the same label
- Dominant language
- C
- Stars
- 4.8k
- Forks
- 523
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 9
Description
**Describe the bug**
Hi!
When two differently-named node variables in a MATCH clause share the same label (e.g. v2:v_3 and v3:v_3), Apache AGE allows both variables to bind to the same node. This violates the openCypher specification, which states that differently-named node variables in a MATCH pattern must bind to distinct nodes. As a result, adding an explicit WHERE v2 <> v3 filter changes the result set, when it should be redundant.
Not sure if this is an intended deviation or not, couldn't find details in the documentation or online.
Thanks!
**How are you accessing AGE (Command line, driver, etc.)?**
- DBeaver (PostgreSQL JDBC driver)
**What data setup do we need to do?**
```pgsql
...
SELECT * FROM cypher('test_graph', $$
CREATE (a:v_1 {id: 1}),
(b:v_3 {id: 2}),
(c:v_3 {id: 3}),
(a)-[:e_3]->(b),
(a)-[:e_3]->(c)
$$) AS (result agtype);
...
```
**What is the command that caused the error?**
```pgsql
--Query A
SELECT * FROM cypher('test_graph', $$
MATCH (v0:v_1)-[:e_3]->(v2:v_3), (v0)-[:e_3]->(v3:v_3)
RETURN v2.id AS v2_id, v3.id AS v3_id
$$) AS (v2_id agtype, v3_id agtype);
--Query B
SELECT * FROM cypher('test_graph', $$
MATCH (v0:v_1)-[:e_3]->(v2:v_3), (v0)-[:e_3]->(v3:v_3)
WHERE v2 <> v3
RETURN v2.id AS v2_id, v3.id AS v3_id
$$) AS (v2_id agtype, v3_id agtype);
```
```
Query A returns 4 rows
Query B returns 2 rows
```
**Expected behavior**
Both queries should return identical results. Per the openCypher specification, differently-named node variables within a MATCH pattern must bind to distinct nodes. The WHERE v2 <> v3 filter should therefore be redundant and have no effect on the result.
Neo4j returns 2 rows for both queries
**Environment (please complete the following information):**
AGE version: apache/age:latest (Docker image)
Image tag: apache/age@sha256:4241e2d8bb86a6b2ea44e9ad06c73856e12b209de295124603a599dd7feb70eb
PostgreSQL version: bundled with apache/age:latest
OS / Platform: Docker (linux/amd64, via --platform linux/amd64)
Contributor guide
Assessment
This issue has not been assessed yet.