Skip to content

Shared relationship variable across pattern parts falls back to a cross join #58

Closed

Description

@prrao87

Problem

A relationship variable reused in two comma-separated pattern parts should join those parts on that one relationship. Instead, the planner joins them with a cross join and returns every combination.

Reproduction

import pyarrow as pa
from lance_csr import CypherEngine, GraphConfig

config = (
    GraphConfig.builder()
    .node_table("Person", "id")
    .rel_table("KNOWS", "Person", "Person", "src", "dst")
    .build()
)
people = pa.table({"id": [1, 2, 3, 4], "name": ["A", "B", "C", "D"]})
engine = CypherEngine(config, {"Person": people, "KNOWS": pa.table({"src": [1, 2], "dst": [2, 3]})})
engine.execute(
    "MATCH (a:Person)-[r:KNOWS]->(b:Person), (c:Person)-[r]->(d:Person) "
    "RETURN a.name AS name ORDER BY name"
).to_pylist()

This returns 8 rows (A four times and B four times); openCypher returns 2 (A and B). The result is the same with and without use_csr=True.

Cause

The logical planner chooses a cross join for the two pattern parts before join keys are inferred, so the shared relationship variable never contributes its endpoint columns as keys. infer_join_keys itself handles relationship variables correctly; a planner test covers it since #51.

Suggested fix

When comma-separated pattern parts share a relationship variable, plan an inner join on that relationship's endpoint columns instead of a cross join.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions