Skip to content

Indexed point lookup is 1.8-2.2x slower in Cypher than the same query in SQL (26.8.1 and 26.10.1-SNAPSHOT); both use the index #8132

Closed

Description

@tae898

Summary

An indexed point lookup costs about 1.8-2.2x in Cypher versus the identical lookup in SQL, on the same database and the same unique index. #1998 was closed with "New cypher engine is much faster than the old one, on par with SQL now", so this is offered as a query shape where the parity does not yet hold, rather than as a new report of the old problem.

Both paths use the index: across a 10x larger corpus the Cypher p50 is almost flat (1.092 -> 1.109 ms) and SQL grows slightly (0.493 -> 0.611 ms), so this is a constant factor in the Cypher path rather than a planning or index-selection difference. That is the part I think is actionable.

Measurements

Java, one file, engine API, database on ext4. Same records, same UNIQUE index, same iteration count (300, first 30 discarded), only the query language differs.

build corpus Cypher p50 SQL p50 ratio
26.10.1-SNAPSHOT 20,000 1.0921 ms 0.4930 ms 2.22x
26.10.1-SNAPSHOT 200,000 1.1085 ms 0.6105 ms 1.82x
26.8.1 200,000 0.9185 ms 0.4731 ms 1.94x

The two queries:

MATCH (p:Person) WHERE p.id = <id> RETURN p.name, p.age
SELECT name, age FROM Person WHERE id = <id>

Where it shows up

I maintain a cross-engine benchmark, and this is roughly half of ArcadeDB's gap on an indexed point lookup against other embedded graph engines. For context, p50 on the same corpus and host, all embedded, all asked the same Cypher text where they speak Cypher: SurrealDB 0.044 ms, FalkorDB 0.121 ms, Memgraph 0.140 ms, LadybugDB 0.161 ms, ArcadeDB 0.490 ms, ArangoDB 0.812 ms, Neo4j 6.155 ms.

ArcadeDB is well ahead of Neo4j here and behind the faster embedded engines; closing the Cypher-to-SQL factor would move it a meaningful part of that distance. Those cross-engine numbers come from my harness on my hardware and are offered only as motivation -- the claim in this issue is the controlled SQL-vs-Cypher comparison above, which is self-contained.

Reproduction

import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.query.sql.executor.ResultSet;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

public class CypherPointLookupRepro {
  static final int N = Integer.getInteger("repro.n", 20000);
  static final int ITERS = Integer.getInteger("repro.iters", 300);
  static final int WARMUP = 30;

  public static void main(String[] args) throws Exception {
    final Path dir = Path.of(System.getProperty("repro.dir", "/data"), "cypherpoint" + N);
    deleteTree(dir);
    Files.createDirectories(dir.getParent());

    try (DatabaseFactory factory = new DatabaseFactory(dir.toString())) {
      final Database db = factory.create();
      db.command("sql", "CREATE VERTEX TYPE Person");
      db.command("sql", "CREATE PROPERTY Person.id INTEGER");
      db.command("sql", "CREATE INDEX ON Person (id) UNIQUE");

      db.begin();
      for (int i = 0; i < N; i++) {
        db.command("sql", "INSERT INTO Person SET id = " + i
            + ", name = 'p" + i + "', age = " + (20 + i % 50));
        if (i % 5000 == 4999) { db.commit(); db.begin(); }
      }
      db.commit();

      final double[] cy = time(db, true);
      final double[] sq = time(db, false);
      db.close();

      System.out.printf("RESULT n=%d iters=%d  cypher p50=%.4fms p99=%.4fms  "
              + "sql p50=%.4fms p99=%.4fms  ratio p50=%.2fx%n",
          N, ITERS - WARMUP, cy[0], cy[1], sq[0], sq[1], cy[0] / sq[0]);
    }
  }

  static double[] time(final Database db, final boolean cypher) {
    final List<Double> lat = new ArrayList<>();
    for (int k = 0; k < ITERS; k++) {
      final int id = k % N;
      final String lang = cypher ? "opencypher" : "sql";
      final String q = cypher
          ? "MATCH (p:Person) WHERE p.id = " + id + " RETURN p.name, p.age"
          : "SELECT name, age FROM Person WHERE id = " + id;
      final long t0 = System.nanoTime();
      try (ResultSet rs = db.query(lang, q)) {
        while (rs.hasNext()) rs.next();
      }
      if (k >= WARMUP) lat.add((System.nanoTime() - t0) / 1_000_000.0);
    }
    final double[] a = lat.stream().mapToDouble(Double::doubleValue).sorted().toArray();
    return new double[] { a[a.length / 2], a[(int) (a.length * 0.99)] };
  }

  static void deleteTree(final Path p) throws Exception {
    if (!Files.exists(p)) return;
    try (var w = Files.walk(p)) {
      w.sorted((x, y) -> y.getNameCount() - x.getNameCount())
       .forEach(f -> { try { Files.deleteIfExists(f); } catch (Exception ignored) { } });
    }
  }
}
javac -cp '/home/arcadedb/lib/*' CypherPointLookupRepro.java
java -cp '/home/arcadedb/lib/*:.' -Drepro.dir=/data -Drepro.n=20000  CypherPointLookupRepro
java -cp '/home/arcadedb/lib/*:.' -Drepro.dir=/data -Drepro.n=200000 CypherPointLookupRepro

What this does not claim

Only that the ratio exists and is stable. I have not profiled where the time goes, so whether it is parse, plan, or result materialisation is open -- if a translation layer is expected to cost this much, that is a fair answer and worth knowing.

Environment

Ubuntu 26.04, Linux 7.0, Docker 29, ext4 on NVMe, JDK 21 (the images' own), container pinned to six cores with 8 GB, -Xmx4g.

Activity

  1. added
    severity:minor
    on Sep 22, 2026
  2. added this to the 26.10.1 milestone on Sep 22, 2026
  3. self-assigned this
    on Sep 22, 2026
  4. added
    in progress
    on Sep 22, 2026
  5. added a commit that references this issue on Sep 22, 2026
  6. lvca commented on Sep 22, 2026

    @lvca
    Member

    Improved in #8208, released in 26.10.1. Thanks for the careful, self-contained benchmark - it made this
    easy to act on.

    Profiling confirmed your reading that this is a constant factor, and located it: about 85% of the time went
    into parsing the query text, and almost none into actually running it. Parsed queries are cached by
    their exact text, so embedding the id directly in the query (WHERE p.id = 1234) produces a new text every
    time and never reuses the cache.

    Two findings:

    1. The Cypher parser is now materially faster. It was repeating the same searches over the query's
    syntax tree dozens of times, once per level of expression nesting, and building throwaway strings on the
    way. On your 20,000-row shape, with 20,000 distinct query texts, the Cypher path dropped from ~660ms to
    ~385ms total - the SQL path is unchanged - taking the ratio from ~4.4x to ~2.6x on our hardware. (We measure
    a higher starting ratio than you do because our loop never reuses a query text; the improvement is the part
    that transfers.)

    2. Use parameters, and the gap disappears entirely. With $id instead of an embedded literal, the
    parse happens once and is reused. On the same machine:

    MATCH (p:Person) WHERE p.id = $id RETURN p.name, p.age    -- 0.004 ms
    SELECT name, age FROM Person WHERE id = :id               -- 0.007 ms
    

    Cypher is faster than SQL there. This is worth changing in your benchmark harness regardless of engine -
    it is also how you would write the query in an application, and it avoids filling the query cache with
    thousands of single-use entries.


    ❤️ 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.

  7. removed
    in progress
    on Sep 22, 2026
  8. tae898 commented on Sep 22, 2026

    @tae898
    ContributorAuthor

    Verified, and your second point is the one that matters for me — you were right that it belongs in my harness regardless of engine.

    Ran four arms on the same database, same unique index, same 20,000 records, 270 timed iterations each, on 26.10.1-SNAPSHOT with #8208:

    p50 p99
    Cypher, embedded literal 0.8702 ms 3.3764 ms
    SQL, embedded literal 0.4810 ms 0.9204 ms
    Cypher, $id parameter 0.0907 ms 0.5563 ms
    SQL, :id parameter 0.0910 ms 0.2707 ms

    With parameters the ratio is 1.00x — 0.0907 against 0.0910, indistinguishable. And both languages get faster, not just Cypher: 9.6x for Cypher and 5.3x for SQL. So the residual gap I filed was a parse-cache artifact almost entirely, which is what your profile said.

    This is a defect in my benchmark, and a bigger one than the issue I filed. My graph lane builds every read from one shared template with the id interpolated into the query text, so every Cypher engine on that table — ArcadeDB, Neo4j, Memgraph, FalkorDB, LadybugDB — is asked with a fresh query string each iteration and none of them reuses a parsed plan. The published point-lookup column is therefore substantially a comparison of parsers rather than of execution, and the penalty is not uniform across engines. I am switching the lane to parameters at my next re-pin, which is when that table is re-measured anyway.

    Worth saying plainly: the issue I filed was "Cypher is 1.8-2.2x slower than SQL here", and the more accurate statement turns out to be "my harness was measuring parsing, and with parameters the two are the same speed". Your fix is still real — the parser got materially faster — but I would not want the original framing left standing without this correction attached.

    The page will pick both up at the re-pin rather than now; the campaign running today holds a single engine from first cell to last, so I do not swap wheels into it mid-run.

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

Metadata

Metadata

Assignees

Labels

opencypherperformanceseverity:minorsql

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions