Repository navigation
Description
Found while verifying PR #9288, which fixes #9277 and #9278. These shapes are not about the labels or the property maps that PR is about: they answer the same on 26.10.1, on main before the PR, and on the PR head.
A MATCH chain that ends in count(*) with a WHERE NOT (a)-[:K]-(b) pattern predicate takes the COUNT ANTI-JOIN CHAIN push-down, and the same WHERE after a WITH takes the row pipeline. For the five shapes below the push-down returns a larger count than the row pipeline, with the push-down in the plan. The expected count is computed in the Java program by enumerating the walks with distinct relationships over the edge list.
Reproduction on Temurin 25 and Temurin 21 for main and the PR head (same output on both), and on OpenJDK 25.0.4.1 for the 26.10.1 jars: compile the class below against the engine jars and run it with an empty directory as the argument. The graph is four Person vertices a, b, c, d and one Tag t, with KNOWS edges a-b, b-c, c-d, and a-c, and every person has HAS_INTEREST to t.
import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.database.RID;
import com.arcadedb.graph.MutableVertex;
import com.arcadedb.query.sql.executor.ResultSet;
import java.util.*;
/**
* The shapes in which the COUNT ANTI-JOIN CHAIN push-down still answers differently from the row pipeline after PR #9288, none of them about the labels or the
* modifiers that PR is about (they answer the same on main cbf701d66e): minimal deterministic repros found by the randomized differentials (AntiJoinGeneral,
* AdjacentCases). Written for the verification of that PR.
*
* java AntiJoinShapes <dbDir>
*
* Graph: 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_INTEREST t. Each query runs as written
* (a push-down when the plan says COUNT ANTI-JOIN CHAIN), with the same WHERE after a WITH (the row pipeline), and the expected count is computed in Java by
* enumerating the walks with distinct relationships (Cypher semantics) over the edge list above.
*/
public class AntiJoinShapes {
static final String[] NAMES = { "a", "b", "c", "d" };
static final int[][] EDGES = { { 0, 1 }, { 1, 2 }, { 2, 3 }, { 0, 2 } };
static Database db;
static boolean connected(final int x, final int y) {
for (final int[] e : EDGES)
if (e[0] == x && e[1] == y || e[0] == y && e[1] == x)
return true;
return false;
}
/** all walks of k edges, distinct edges, over the undirected edge list; the predicate decides on the node list */
static long expected(final int k, final java.util.function.Predicate<int[]> keep) {
final long[] n = { 0 };
for (int s = 0; s < 4; s++)
walk(k, new int[k + 1], new boolean[EDGES.length], 0, s, keep, n);
return n[0];
}
static void walk(final int k, final int[] path, final boolean[] used, final int h, final int at, final java.util.function.Predicate<int[]> keep, final long[] n) {
path[h] = at;
if (h == k) {
if (keep.test(path))
n[0]++;
return;
}
for (int e = 0; e < EDGES.length; e++) {
if (used[e] || EDGES[e][0] != at && EDGES[e][1] != at)
continue;
used[e] = true;
walk(k, path, used, h + 1, EDGES[e][0] == at ? EDGES[e][1] : EDGES[e][0], keep, n);
used[e] = false;
}
}
public static void main(final String[] args) {
System.out.println("engine " + com.arcadedb.Constants.getRawVersion() + " build " + com.arcadedb.Constants.getBuildNumber() + ", java " + System.getProperty("java.version"));
final DatabaseFactory f = new DatabaseFactory(args[0]);
if (f.exists())
f.open().drop();
db = f.create();
for (final String ddl : new String[] { "CREATE VERTEX TYPE Person", "CREATE VERTEX TYPE Tag", "CREATE EDGE TYPE KNOWS", "CREATE EDGE TYPE HAS_INTEREST" })
db.command("sql", ddl);
db.begin();
final RID[] p = new RID[4];
for (int i = 0; i < 4; i++) {
final MutableVertex v = db.newVertex("Person").set("id", (long) i);
v.save();
p[i] = v.getIdentity();
}
final MutableVertex tv = db.newVertex("Tag");
tv.save();
for (final int[] e : EDGES)
p[e[0]].asVertex().newEdge("KNOWS", p[e[1]]).save();
for (int i = 0; i < 4; i++)
p[i].asVertex().newEdge("HAS_INTEREST", tv.getIdentity()).save();
db.commit();
final String P3 = "MATCH (p0:Person)-[:KNOWS]-(p1:Person)-[:KNOWS]-(p2:Person)-[:HAS_INTEREST]->(t:Tag) ";
final String P4 = "MATCH (p0:Person)-[:KNOWS]-(p1:Person)-[:KNOWS]-(p2:Person)-[:KNOWS]-(p3:Person) ";
final Object[][] qs = {
{ "S0 control, LSQB Q9 shape: two hops, NOT (p0)-[:KNOWS]-(p2) AND p0 <> p2", P3, "p0, p1, p2, t", "NOT (p0)-[:KNOWS]-(p2) AND p0 <> p2",
expected(2, w -> !connected(w[0], w[2]) && w[0] != w[2]) },
{ "S1 three KNOWS hops, the last one can reuse the relationship before it (NOT (p0)-[:KNOWS]-(p2) AND p0 <> p2)", P4, "p0, p1, p2, p3", "NOT (p0)-[:KNOWS]-(p2) AND p0 <> p2",
expected(3, w -> !connected(w[0], w[2]) && w[0] != w[2]) },
{ "S2 the inequality is between other nodes than the negated pattern (NOT (p0)-[:KNOWS]-(p2) AND p1 <> p2)", P3, "p0, p1, p2, t", "NOT (p0)-[:KNOWS]-(p2) AND p1 <> p2",
expected(2, w -> !connected(w[0], w[2]) && w[1] != w[2]) },
{ "S3 no inequality: the walk back over the same relationship counts (NOT (p0)-[:KNOWS]-(p2))", P3, "p0, p1, p2, t", "NOT (p0)-[:KNOWS]-(p2)",
expected(2, w -> !connected(w[0], w[2])) },
{ "S4 neither end of the negated pattern is the first node (NOT (p1)-[:KNOWS]-(p3) AND p1 <> p3)", P4, "p0, p1, p2, p3", "NOT (p1)-[:KNOWS]-(p3) AND p1 <> p3",
expected(3, w -> !connected(w[1], w[3]) && w[1] != w[3]) },
{ "S5 an unlabelled middle node and the first node as the target of the negated pattern (NOT (p2)-[:KNOWS]-(p0) AND p2 <> p0)",
"MATCH (p0:Person)-[:KNOWS]-(p1)-[:KNOWS]-(p2:Person)-[:HAS_INTEREST]->(t:Tag) ", "p0, p1, p2, t", "NOT (p2)-[:KNOWS]-(p0) AND p2 <> p0",
expected(2, w -> !connected(w[2], w[0]) && w[2] != w[0]) },
};
for (final Object[] q : qs) {
final String text = q[1] + "WHERE " + q[3] + " RETURN count(*) AS n";
final long asWritten = count(text), rowPipeline = count(q[1] + "WITH " + q[2] + " WHERE " + q[3] + " RETURN count(*) AS n");
String plan;
try (ResultSet rs = db.query("opencypher", "EXPLAIN " + text)) {
plan = rs.getExecutionPlan().map(x -> x.prettyPrint(0, 2)).orElse("");
}
final long exp = (Long) q[4];
System.out.println("SHAPE | " + q[0] + " | expected " + exp + " | row pipeline " + rowPipeline + " | as written " + asWritten + " | " + (asWritten == exp ? "RIGHT" : "WRONG") + " | "
+ (plan.contains("ANTI-JOIN") ? "ANTI-JOIN CHAIN" : "no push-down") + " | " + text);
}
db.drop();
}
static long count(final String q) {
try (ResultSet rs = db.query("opencypher", q)) {
return ((Number) rs.next().getProperty("n")).longValue();
}
}
}Output of the six queries (the first is the control, the two-hop shape the push-down is written for, and it is right):
| WHERE on the chain | expected | row pipeline | 26.10.1 (d36b4ca) | main cbf701d | PR #9288 head 7d69d5f |
|---|---|---|---|---|---|
NOT (p0)-[:KNOWS]-(p2) AND p0 <> p2 on (p0:Person)-[:KNOWS]-(p1:Person)-[:KNOWS]-(p2:Person)-[:HAS_INTEREST]->(t:Tag) (control, the LSQB Q9 shape) |
4 | 4 | 4 | 4 | 4 |
NOT (p0)-[:KNOWS]-(p2) AND p0 <> p2 on (p0:Person)-[:KNOWS]-(p1:Person)-[:KNOWS]-(p2:Person)-[:KNOWS]-(p3:Person) |
2 | 2 | 6 | 6 | 6 |
NOT (p0)-[:KNOWS]-(p2) AND p1 <> p2 on (p0:Person)-[:KNOWS]-(p1:Person)-[:KNOWS]-(p2:Person)-[:HAS_INTEREST]->(t:Tag) |
4 | 4 | 12 | 12 | 12 |
NOT (p0)-[:KNOWS]-(p2) on (p0:Person)-[:KNOWS]-(p1:Person)-[:KNOWS]-(p2:Person)-[:HAS_INTEREST]->(t:Tag) |
4 | 4 | 12 | 12 | 12 |
NOT (p1)-[:KNOWS]-(p3) AND p1 <> p3 on (p0:Person)-[:KNOWS]-(p1:Person)-[:KNOWS]-(p2:Person)-[:KNOWS]-(p3:Person) |
2 | 2 | 10 | 10 | 10 |
NOT (p2)-[:KNOWS]-(p0) AND p2 <> p0 on (p0:Person)-[:KNOWS]-(p1)-[:KNOWS]-(p2:Person)-[:HAS_INTEREST]->(t:Tag) |
4 | 4 | 18 | 18 | 18 |
By my reading of the code (not verified by a patch), the shapes are: (1) more than two hops of the same relationship type, where the tail hop can walk back over the relationship before it, so relationship uniqueness is not applied; (2) an inequality between other nodes than the negated pattern's, which executeOLTP ignores unless it is between position 0 and the check position, and (3) no inequality at all, where the walk back over one relationship counts; (4) neither end of the negated pattern at position 0, which executeGenericAntiJoin hands to executeOLTP; and (5) an unlabelled node in the chain with the first node as the target of the negated pattern, which takes executeOLTPRecursive, where the anti-join set is never applied.
Size of the problem: over random graphs, 3,000 random chain queries per build (every one with the push-down in the plan) answered 1,667 wrong on main before the PR and 1,329 wrong on the PR head, and 2,808 spelled variants differed from the row pipeline in 1,803 cases before the PR and 859 on the PR head. The shape in which the push-down answered right in all of those queries is: two relationships of the anti-join's type before the check position, one end of the negated pattern at position 0, the inequality between the negated pattern's two nodes, and a label on every node of the chain (103 queries pushed down in that shape, 0 wrong).
Suggested direction: decline the push-down for every shape outside that one, the way PR #9288 now declines a differing label or a property map, so these queries take the row pipeline, which is right in all of them. LSQB's Q9 is the right shape and keeps the push-down with an unchanged time on the PR head (ratio of medians 0.99 to 1.04, 10 JVMs per arm, both JDKs).
Activity
known issues: the count push-down is wrong for other chain shapes (up…
docs: known issues fixed in 26.10.1 leave the page with the release; …
tests: the ArcadeData#9277, ArcadeData#9278 and ArcadeData#9281 tripw…
docs: retire stale and duplicate Python bindings pages, fix what drif…
Merge pull request #9299 from ArcadeData/fix/9290-9291-antijoin-count…
lvca commentedon Oct 6, 2026
Fixed in #9299, included in 26.11.1.
The count shortcut for chains ending in
count(*)withWHERE NOT (a)-[:K]-(b)could return larger counts than the normal pipeline. It is now used only for the shape it counts exactly (two hops of the same type, a labelled chain, the inequality between the two ends of the negated pattern); every other shape runs through the normal pipeline. Edges to vertices of another label are no longer counted either.❤️ 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.
tae898 commentedon Oct 6, 2026
Verified at the final head of #9299: all five shapes of this issue now answer the row pipeline's count on both JDKs (6, 12, 12, 10, and 18 before, where 2, 4, 4, 2, and 4 is right), and the LSQB Q9 shape keeps its push-down and its answer. Three kinds of answers still differ from the row pipeline on the shape the PR keeps; none is a regression of #9299, all answer the same on the merge-base, and none is one of the shapes listed here.
A self-loop relationship is counted twice by an undirected hop of the push-down, on a chain hop or on the tail hop: this is Count push-downs over an undirected hop count a self-loop twice (Neo4j and the ordinary pipeline count it once) #9283, still open. Minimal graph for a chain hop: two persons a and b,
b-[:KNOWS]->a,b-[:KNOWS]->b, both with a HAS_INTEREST edge to one Tag;MATCH (p0:Person)-[:KNOWS]-(p1:Person)-[:KNOWS]-(p2:Person)-[:HAS_INTEREST]->(t:Tag) WHERE NOT (p0)-[:KNOWS]->(p2) AND p0 <> p2 RETURN count(*)answers 2 as written and 1 through the row pipeline (with the undirected negated pattern of LSQB Q9 both answer 0). For the tail hop: persons x, y, z withx-[:KNOWS]->y,y-[:KNOWS]->z,z-[:HAS_INTEREST]->zandz-[:HAS_INTEREST]->tag, the tail hop written-[:HAS_INTEREST]-(t): 3 as written, 2 through the row pipeline. These two forms explain every remaining difference of the two matrices below that contain self-loops: the 14 distinct texts (15 queries) that differ in AdjacentCases are 0 on the same graph without its one self-loop relationship, and the 40 queries that differ in TailLabel are 0 when the random graphs have no self-loops.A chain with an unlabelled first node and the inequality written
p2 <> p0(the later node first): the recursive path applies the inequality for one operand order only, so the walk back over the same relationship is counted (two persons and one KNOWS relationship: 2 as written, 0 right). It answers the same on 26.10.1, so it is older than fix: anti-join count push-down shapes and sorted index build for low-cardinality keys (#9290, #9291) #9299; I filed it as openCypher: the COUNT ANTI-JOIN CHAIN push-down with an unlabelled first node ignores the inequality when it is writtenp2 <> p0(later node first), and counts the walk back over the same relationship #9345 with a Java repro and the line ofAntiJoinChainOp.countPathsRecthat checks one operand order.The LSQB Q2 and Q3 count push-downs of openCypher: the COUNT push-downs for LSQB Q2 and Q3 count a parallel or a reciprocal KNOWS edge once, where the row pipeline matches one row per relationship (Q2 only while a Graph Analytical View over every type is READY) #9298 (parallel and reciprocal edges), which are not anti-join shapes; they are the 84 answers that stay wrong in
LsqbDiffbelow, identical on both builds.Post-merge check of #9299 on a laptop, from Java against the engine API, on Temurin 25 and Temurin 21: the merge commit is cc03e79, its first parent (main without the fix) is cdb2df2, and its second parent (the final head of the PR) is 22853f4.
The merge commit's git tree (3e1945861f03453c024f3967f23778e150d1a316) is identical to the final head's tree, so the jars built at the final head are the merged code; only the build stamp's commit SHA differs.
Jars: the CI-built distribution of each commit (engine, server, plugins; the shaded HA jar is left out because it carries its own copy of the engine classes), built by GitHub Actions from the commit. One JVM at a time on two P cores of a shared, throttling laptop,
-Xms1g -Xmx1g, a systemd scope limited to 2 GB. Every run printed the throttle counters; they moved in most of them, so every timing below is a relative comparison and no absolute figure is a result. The answers do not depend on timing.java -versionof the four builds (the same string in both runs of a JDK):-XX:+UseCompactObjectHeaders:openjdk version "25.0.4" 2026-07-21 LTS / OpenJDK Runtime Environment Temurin-25.0.4+7 (build 25.0.4+7-LTS) / OpenJDK 64-Bit Server VM Temurin-25.0.4+7 (build 25.0.4+7-LTS, mixed mode, sharing)openjdk version "21.0.12" 2026-07-21 LTS / OpenJDK Runtime Environment Temurin-21.0.12+8 (build 21.0.12+8-LTS) / OpenJDK 64-Bit Server VM Temurin-21.0.12+8 (build 21.0.12+8-LTS, mixed mode, sharing)-XX:+UseCompactObjectHeaders:openjdk version "25.0.4" 2026-07-21 LTS / OpenJDK Runtime Environment Temurin-25.0.4+7 (build 25.0.4+7-LTS) / OpenJDK 64-Bit Server VM Temurin-25.0.4+7 (build 25.0.4+7-LTS, mixed mode, sharing)openjdk version "21.0.12" 2026-07-21 LTS / OpenJDK Runtime Environment Temurin-21.0.12+8 (build 21.0.12+8-LTS) / OpenJDK 64-Bit Server VM Temurin-21.0.12+8 (build 21.0.12+8-LTS, mixed mode, sharing)The five shapes of this issue (
AntiJoinShapes, byte for byte the repro in the issue, sha256 prefix6ffac903b2cb9f9e: a four-person graph, the right answer is the enumeration of walks over distinct relationships in Java, and the row pipeline gives it):p1 <> p2)NOT (p1)-[:KNOWS]-(p3) AND p1 <> p3)NOT (p0)-[:KNOWS]-(p2) AND p0 <> p2)Broader matrices (my own Java programs against the engine API: random graph generators, each query run as written and compared with the count of the same WHERE after a WITH, which is the row pipeline, or with a brute force in Java; every query that is wrong on the head is a count push-down in its plan; the repros of the answers that stay wrong are in this reply and in #9345):
The push-down is taken in 720 of the 2,700 AntiJoinDiff queries on both builds and in 146 of the 3,000 AntiJoinGeneral queries on the head (2,039 on the merge-base). The row sets of the 8,800
MatchDiffqueries (40 random graphs) are identical on the two builds except for one query where the merge-base's push-down differed from its own row pipeline and the head equals it.LSQB: Q9 keeps its push-down and its answer. On the generated Q9 graph (1,000 persons, 2,000 KNOWS edges, 24 interests each; seed 11) the four spellings of
Q9Steady(node inequality, property inequality on a mandatory, not null, unique property, end labels equal to the chain's, node inequality again) answer 398,544 on both builds, which is the row pipeline's answer, and the plan holds the COUNT ANTI-JOIN CHAIN for the node inequality, the labelled, and the mandatory-property spellings. The benchmark's own texts for Q5, Q6, Q8, and Q9 (a property inequalitya.id <> b.id) are planned as before on both builds (the row pipeline). Of the 24 plan lines ofPlanProbeone differs: LSQB Q8 written with the vertex inequalitytag1 <> tag2(the engine's own runner text) no longer takes the push-down. On random graphs with parallel edges and a view over every type the merge-base's push-down for that text was wrong in 13 of 24 graphs (52 wrong answers over the seven Q8 spellings ofQ8Diff, 336 queries), so the decline removes wrong answers; its cost is in the last table.LsqbDiff(12 random LDBC-like graphs with hubs, parallel, reciprocal, and self-loop edges, 41 query texts, four situations: no view, a Person and KNOWS view, a view over every type, and that view from four threads; default, simple-graph, and memory-pressure modes with-Xmx640m): 1,968 answers per mode and JDK, no answer changed from right to wrong, 52 (default and pressure modes) and 48 (simple graphs) changed from wrong to right, all in theq9-no-inequalityandq9-other-types-createdtexts.Cost of the newly declined shapes, relative and laptop-only (
DeclinedCost: the Q9 graph plus 2,000 messages and 3,000 comments for Q8, 8 untimed and 20 timed runs per query per JVM, 10 JVMs per arm and JDK interleaved, the first round dropped, median per JVM, bootstrap 95% interval of the ratio of medians; I call nothing under 1.3x a slowdown). The head arm of this table is the jars of 0e7ecdb, an earlier head of the PR: the compare between that commit and the final head touches only the bulk loader, the external sorter, and tests, so the anti-join code is identical.p1 <> p2(S2)p1andp3(S4)The shapes that lose their push-down run on the row pipeline and cost the ratios above, 19 to 63 times for S1, S2, S3, S5, and the four-hop chain, and 1.8 times for Q8 with the vertex inequality. S4 was already on the slow generic path on the merge-base and is unchanged. The Q9 spellings that stay on the push-down measure 1.1 to 1.2 times (the last Q9 row has an interval above 1.0 on both JDKs but stays under the 1.3x bar); the tail degree now walks the tail neighbours to apply the label of the tail node, which is the likely cause. The property-inequality Q8 that the benchmark sends is unchanged.
Not checked: LDBC data and the benchmark's own harness (only the LSQB texts on generated graphs), the server endpoints and the other query languages, the shaded HA jar, chains of more than four hops, views with update modes other than OFF, edge properties other than a
wmap, relationship uniqueness across several MATCH clauses, and graphs above 2,000 persons for the timings.CI: the test step tolerates a suite with no expected failures (grep e…
tests: the ArcadeData#9290 tripwires become plain regression tests (A…
docs: retire stale and duplicate Python bindings pages, fix what drif…
docs: known issues says ArcadeData#9290 is fixed upstream (ArcadeData…
docs: retire stale and duplicate Python bindings pages, fix what drif…
fix: anti-join count push-down declines shapes it cannot count exactl…
perf: LSQB Q8 takes the anti-join count push-down again, with an exac…