Skip to content
This repository was archived by the owner on Nov 21, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions bindings/python/docs/guide/known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,48 @@ that are not affected, and has strict `xfail` tests of the wrong counts; they st
suite when the engine fixes them, which is the cue to remove this entry.


## An openCypher count with a negated pattern is wrong for other shapes of the chain

ArcadeDB [#9290](https://github.com/ArcadeData/arcadedb/issues/9290); measured through the
bindings on the 26.10.1 wheel, and in Java on 26.10.1, on upstream main cbf701d66e, and on the
head of the upstream fix for the entry above (7d69d5f534), on Temurin 21 and 25, with the same
answers. Open.

The count push-down of the entry above (`EXPLAIN` lists `COUNT ANTI-JOIN CHAIN`) is also wrong
for chains that are not the two-hop shape it is written for. On four people with `KNOWS` a-b,
b-c, c-d, and a-c, each interested in one tag, these counted more than the right number, with
the push-down in the plan:

| Chain and `WHERE` | Counted | Right |
| --- | --- | --- |
| three `KNOWS` hops, `NOT (p0)-[:KNOWS]-(p2) AND p0 <> p2` | 6 | 2 |
| two hops and a tag, `NOT (p0)-[:KNOWS]-(p2) AND p1 <> p2` (an inequality between other nodes) | 12 | 4 |
| the same chain, `NOT (p0)-[:KNOWS]-(p2)` (no inequality) | 12 | 4 |
| three `KNOWS` hops, `NOT (p1)-[:KNOWS]-(p3) AND p1 <> p3` (the pattern not at the first node) | 10 | 2 |
| an unlabelled middle node, `NOT (p2)-[:KNOWS]-(p0) AND p2 <> p0` | 18 | 4 |

The two-hop chain with a label on every node, the negated pattern between its first and third
node, and the inequality between the same two (the shape of the LSQB benchmark's Q9) counted
right (4). Put the variables through a `WITH` before the `WHERE`, as above; the row pipeline
counted the right number for every shape in the table:

```python
chain = "MATCH (p0:Person)-[:KNOWS]-(p1:Person)-[:KNOWS]-(p2:Person)-[:HAS_INTEREST]->(t:Tag) "
n = (
db.query(
"opencypher",
chain + "WITH p0, p1, p2, t WHERE NOT (p0)-[:KNOWS]-(p2) RETURN count(*) AS n",
)
.first()
.get("n")
)
```

Tests: `tests/test_count_pushdown_known_issues.py` checks the `WITH` workaround and the unaffected
shape, and has strict `xfail` tests of the wrong counts; they start failing the suite when the
engine fixes them, which is the cue to remove this entry.


## `sum()` and `avg()` over a `BYTE` property raise `IllegalArgumentException`

ArcadeDB [#9281](https://github.com/ArcadeData/arcadedb/issues/9281); measured through the
Expand Down
118 changes: 117 additions & 1 deletion bindings/python/tests/test_count_pushdown_known_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
Upstream: ArcadeData/arcadedb #9277 (the push-down counts the wrong vertices when the far end of the
chain has another label than the first hop's target; the change for #9203 let `id(a) <> id(b)` reach
it), #9278 (the push-down ignores the property map of the negated pattern's relationship), #9281
(`sum()` and `avg()` over a `BYTE` property raise `IllegalArgumentException`).
(`sum()` and `avg()` over a `BYTE` property raise `IllegalArgumentException`), #9290 (the push-down
counts wrong for chains with more than two hops of one type, an inequality between other nodes, no
inequality, a negated pattern away from the first node, or an unlabelled node with the first node as
the target).
"""

import arcadedb_embedded as arcadedb
Expand Down Expand Up @@ -326,3 +329,116 @@ def test_converting_a_byte_to_an_integer_before_the_aggregate_works(
with arcadedb.create_database(temp_db_path) as db:
_byte_types(db)
assert _result_or_error(db, language, query) == expected


# ---------------------------------------------------------------------------------------------
# #9290: other shapes of the chain
# ---------------------------------------------------------------------------------------------

SHAPES_REASON = (
"ArcadeData/arcadedb#9290: the COUNT ANTI-JOIN CHAIN push-down counts more than the row "
"pipeline for chains with more than two hops of one type, an inequality between other nodes "
"than the negated pattern's, no inequality, a negated pattern away from the first node, or an "
"unlabelled node with the first node as the target"
)
shapes_bug = pytest.mark.xfail(strict=True, raises=AssertionError, reason=SHAPES_REASON)

_P3 = "MATCH (p0:Person)-[:KNOWS]-(p1:Person)-[:KNOWS]-(p2:Person)-[:HAS_INTEREST]->(t:Tag) "
_P4 = (
"MATCH (p0:Person)-[:KNOWS]-(p1:Person)-[:KNOWS]-(p2:Person)-[:KNOWS]-(p3:Person) "
)
_P3_UNLABELLED = (
"MATCH (p0:Person)-[:KNOWS]-(p1)-[:KNOWS]-(p2:Person)-[:HAS_INTEREST]->(t:Tag) "
)


def _shapes_graph(db):
"""Four Person a, b, c, d and one Tag t; KNOWS a-b, b-c, c-d, a-c (stored one way, matched both
ways); every Person has HAS_INTEREST to t. The expected counts below enumerate the walks with
distinct relationships (Cypher semantics) over this edge list."""
for ddl in (
"CREATE VERTEX TYPE Person",
"CREATE VERTEX TYPE Tag",
"CREATE EDGE TYPE KNOWS",
"CREATE EDGE TYPE HAS_INTEREST",
):
db.command("sql", ddl)
with db.transaction():
people = [db.new_vertex("Person").set("id", i).save() for i in range(4)]
tag = db.new_vertex("Tag").save()
for a, b in ((0, 1), (1, 2), (2, 3), (0, 2)):
people[a].new_edge("KNOWS", people[b]).save()
for person in people:
person.new_edge("HAS_INTEREST", tag).save()


# (match, variables kept by the WITH, where, expected count)
_SHAPES = [
pytest.param(
_P4,
"p0, p1, p2, p3",
"NOT (p0)-[:KNOWS]-(p2) AND p0 <> p2",
2,
id="three-hops-of-one-type",
),
pytest.param(
_P3,
"p0, p1, p2, t",
"NOT (p0)-[:KNOWS]-(p2) AND p1 <> p2",
4,
id="inequality-between-other-nodes",
),
pytest.param(_P3, "p0, p1, p2, t", "NOT (p0)-[:KNOWS]-(p2)", 4, id="no-inequality"),
pytest.param(
_P4,
"p0, p1, p2, p3",
"NOT (p1)-[:KNOWS]-(p3) AND p1 <> p3",
2,
id="negated-pattern-away-from-the-first-node",
),
pytest.param(
_P3_UNLABELLED,
"p0, p1, p2, t",
"NOT (p2)-[:KNOWS]-(p0) AND p2 <> p0",
4,
id="unlabelled-node-and-first-node-as-target",
),
]


@pytest.mark.parametrize("match, variables, where, expected", _SHAPES)
@shapes_bug
def test_the_push_down_counts_the_other_shapes_like_the_row_pipeline(
temp_db_path, match, variables, where, expected
):
"""#9290: each shape is answered by the push-down with a larger count than the row pipeline's."""
with arcadedb.create_database(temp_db_path) as db:
_shapes_graph(db)
written = f"{match}WHERE {where} RETURN count(*) AS n" # nosec B608
_require_anti_join_plan(db, written)
assert _count(db, written) == expected


@pytest.mark.parametrize("match, variables, where, expected", _SHAPES)
def test_with_before_the_where_gives_the_row_pipeline_count_for_the_other_shapes(
temp_db_path, match, variables, where, expected
):
"""known-issues.md (#9290): `WITH <the chain's variables>` before the WHERE keeps the query
off the push-down and gives the right count."""
with arcadedb.create_database(temp_db_path) as db:
_shapes_graph(db)
row_pipeline = (
f"{match}WITH {variables} WHERE {where} RETURN count(*) AS n" # nosec B608
)
assert _count(db, row_pipeline) == expected


def test_the_two_hop_shape_the_push_down_is_written_for_is_not_affected(temp_db_path):
"""#9290: two hops, the negated pattern between the first and third node, the inequality between
the same two, and a label on every node (the LSQB Q9 shape) counts right through the push-down.
"""
with arcadedb.create_database(temp_db_path) as db:
_shapes_graph(db)
written = f"{_P3}WHERE NOT (p0)-[:KNOWS]-(p2) AND p0 <> p2 RETURN count(*) AS n" # nosec B608
_require_anti_join_plan(db, written)
assert _count(db, written) == 4
Loading