What is compiled
What each statement gives on each store is set out in
drivine-cypher-spec, which all three Drivine libraries run in
their tests. Each release of drivine4j passes the version of it named in that release’s
src/test/resources/cypher/VERSION, as does each checkout. It covers reads and writes (CREATE, MERGE, SET,
REMOVE, DELETE), OPTIONAL MATCH, aggregation, UNION, CALL { … }, EXISTS { … }, FOREACH,
variable-length relationships, quantified path patterns, shortestPath, list comprehensions and openCypher’s temporal
values.
Cypher the compiler doesn’t take is refused by name before anything is sent, with a DrivineException such as
SKIP or LIMIT of an expression is Cypher, and is not compiled to SQL yet. Text that isn’t Cypher is refused with the
place in the statement it stands at.
Neo4j’s schema DDL (CREATE INDEX, CREATE CONSTRAINT, DROP INDEX, DROP CONSTRAINT, CALL db.awaitIndexes) is no
query: given to a PersistenceManager, it is applied to the store’s schema, as
Neo4j schema DDL on the SQL stores describes, and the
compiler alone refuses it.
A statement is translated as written, and nothing is added to it. So a write of a
@CaseInsensitive property leaves the lowercased
copy the object managers keep beside it as it was, on these stores as on the graph engines: set the copy in the same
statement, or refill it afterwards (how).
A node’s id, id(n) or elementId(n), is the key of its row, and a relationship’s is the key of its own. Where the
row must pass a comparison of one by = or IN, as a WHERE or one of its conditions joined by AND must be passed,
the store reads the row by that key: MATCH (n) WHERE id(n) = $id, MATCH (n) WHERE id(n) IN $ids and
UNWIND $ids AS i MATCH (n) WHERE id(n) = i read a row for each id, not every node for each. The comparison is still
Cypher’s, so 5.0 is the id 5, and a text, a list or null is no id. Under NOT, beside an OR, or as a value
(RETURN id(n) = $id), it reads every row it compares, as an expression of a property does. On Oracle a node of a
label the pattern names (MATCH (n:Person) WHERE id(n) = $id) found so tests its labels in a form the index over labels
can’t answer, so Oracle reads it by the key too, not every node of the label
(details).
A DELETE deletes the nodes and relationships of all its rows at once, a statement for each table, not one for each
row: the relationships first, then the nodes, a node’s relationships going with it where it is DETACH. One that ends
the statement and deletes one variable, a node with DETACH or a relationship, of a match that binds only nodes and
relationships, reads the ids from the match itself, so MATCH (n) DETACH DELETE n is one SQL DELETE. In a FOREACH
or a CALL { … } that writes, each row is still written alone, as in Cypher.
Any other write, a CREATE, MERGE, SET or REMOVE, and a CALL { … } that writes and returns, is a loop over its
rows, and keeps each row it leaves in a list of the store’s own that grows in place: an array of jsonb in PL/pgSQL, a
JSON_ARRAY_T in PL/SQL, a list in Drivine’s function on SQLite. It is read as one JSON list once the loop is done, so
the loop takes time in proportion to its rows. Appended to a JSON list, each row copied the list, and ten times the rows
took about a hundred times as long (#588). On Oracle, a query
that reads the row a FOREACH or a CALL { … } is written for is planned for one row (CARDINALITY): planned for the
8,168 rows Oracle guesses a JSON_TABLE of a variable holds, it read every node for each row, by a hash join.
A value whose kind the statement fixes (a literal, a list or a map written, a function that gives a float such as
toFloat() or round(), arithmetic of such numbers, a CASE whose values are of one such kind, an item an UNWIND
takes from a list written of them, or a variable a WITH binds to one) is refused where an operator or a function takes
another kind, as Neo4j refuses it when it plans the statement: RETURN 123 AND true fails with
AND takes a truth value, not an integer, as in Neo4j., and so do WITH 123 AS x RETURN x.num, RETURN 1 IN 'foo' and
RETURN left('hello', toFloat(2)). A step of 0 in range(), written or given, a parameter given as
the index of a list or a map written that isn’t indexed by its kind, as in WITH [1] AS l RETURN l[$k] given a text,
and a map, or a list of maps or of lists, written in SET, are refused too, though Neo4j fails on them only when a row
reaches them: such a statement is refused even where it would match nothing. A statement is compiled for each call,
with the parameters it is given, so a value given refuses that call alone. A value whose kind is known only when the
row is read, such as a property or a parameter, is compiled: where it is of the wrong kind, the statement may give null
where Neo4j fails.
A variable used as two kinds is refused too, as Neo4j refuses it: MATCH (a)-[a]->() or WITH true AS n MATCH (n)
fails with a is a node, and is used as a relationship: a variable is of one kind, as in Neo4j. So is one a pattern
makes where it is bound already: MATCH (a) CREATE (a), a path variable bound before its MATCH, or a relationship
variable bound as something else. A pattern used as an expression, which tests for a match and binds nothing, is
refused where it names a variable not bound before it, as Neo4j refuses it: MATCH (n) WHERE (n)-[r]->() RETURN n
fails with r is not defined: a pattern used as an expression binds no new variable, as in Neo4j. …, where
EXISTS { (n)-[r]->() } may bind one. So is size() of a pattern, size((a)-->()): COUNT { … } counts its matches.
A MERGE fails where it would make a node or a relationship whose pattern gives a property that is null, as Neo4j
fails it, since no MERGE would find it again: MERGE (n:X {a: null}) fails with Cannot merge the following node because of null property value for 'a'., wrapped as each store raises an error, and writes nothing. It fails only as
a row makes it, so not over no rows. On Oracle, which stores NaN, so does one whose property is NaN. On
Postgres and SQLite, which store no NaN, such a
MERGE fails too, as any write of NaN does there, with other words.

