Skip to content

Oracle

Oracle Database 23.9 or later, through oracledb in thin mode. Oracle doesn’t speak Cypher: Drivine reads the graph with SQL/PGQ (GRAPH_TABLE) and writes it as rows. Models, the DSL and the object manager are the same as on the graph engines.

Drivine needs 23.9 because Cypher’s randomUUID() is Oracle’s UUID(), a random version 4 UUID, which Oracle added in 23.9. A provider reads the version the driver found on its first connection, which needs no grant. On an older Oracle, plain SQL still runs, and a Cypher statement is refused with the version found.

Terminal window
DATABASE_TYPE=ORACLE
DATABASE_HOST=localhost
DATABASE_PORT=1521 # the default
DATABASE_NAME=FREEPDB1 # the service: required
DATABASE_USER=app
DATABASE_PASSWORD=secret
DATABASE_DEFAULT_GRAPH_PATH=drivine # names the property graph and its tables; this is the default

The graph’s name names tables, so it is letters, digits and underscores, begins with a letter, and is at most 114 characters. In code, it is defaultGraphPath on the connection’s properties, or on the builder: DatabaseRegistry.getInstance().builder().withProperties(properties).defaultGraphPath('tenant_a').register('TENANT_A'). Two databases over one Oracle service, each naming its own graph, keep apart: each manager reads, writes and indexes its own graph’s tables alone.

How a graph is stored. Two tables and a property graph over them, made when a manager first speaks to the graph: <graph>_node (nid, labels, props, stamp) and <graph>_edge (eid, src, dst, type, props), with labels and props as JSON. Labels, property names and relationship types are data, so @NodeLabels, @PropertyBag and edges work as they do elsewhere. A node’s stamp is the stamp column. A third table, <graph>_schema, records the indexes and constraints Drivine made, as drivine4j records them. The layout is drivine4j’s, so the JVM, Node and Python read one store, and each sees and drops the indexes the others made, and makes none beside them.

Beside the tables the graph is made with functions: <graph>_nulls_equal, by which a compiled Cypher statement compares two lists or maps that may hold a null (see the notes in Cypher on Oracle and Postgres), <graph>_era and <graph>_era_date, which renumber a year before 1 between Cypher’s numbering and Oracle’s as a date or a moment is read and written, and <graph>_temporal_arith, which works out +, -, * and / of a temporal value read from the store. Making them takes CREATE PROCEDURE, which the RESOURCE role grants, as well as the CREATE TABLE the tables take. A store an earlier version made gains those it lacks the next time a connection to the graph first connects. Where the user that makes the graph may not make a function, the graph is made without them, and Drivine logs a warning once for the graph when a statement would call one, and looks for it again a minute later. Without <graph>_nulls_equal, a statement that writes, or the step of a reduce, compares two lists or maps that hold a null and differ as JSON as false, where Cypher may give null ([null] = [1]), and a read declares the function itself. Without the era functions, a statement gives the same rows, renumbering a year inline, but Oracle takes longer to plan one of temporal arithmetic: seconds, and over a minute for a moment two CALLs deep. A statement of the query DSL that would call one the session may not call is refused, saying which (see the notes below).

A graph an earlier Drivine wrote. Oracle, Postgres and SQLite hold each value in store layout 2, as the shared compiler writes it, and as drivine4j and drivine-python write it: a Date a save writes, and a temporal value a Cypher statement writes, as a tagged map of its ISO 8601 text and the key it orders by ({"$t": "datetime", "v": "…", "s": "…"}), read back as its text, which a field declared a Date loads as a Date (see Object Manager), and a property or map key whose name begins with $ under one more $. The graph’s stamp, its DrivineStore node, names its layout, and the provider reads it on its first connection, before anything is made. A graph an earlier Drivine wrote in layout 1 that holds no node but Drivine’s own, its stamp and its schema marker, has that layout’s indexes dropped and is stamped layout 2. One that holds the application’s nodes is refused, on that connection and every one after it, with a StoreLayoutError that names the graph and says what to do: export it with the Drivine version that wrote it, and import it with this one, or migrate it in place (below). A graph a later Drivine stamped with a later layout is refused too. The error’s graph names the graph, from the earlier layout it was written in, where it holds values, and inProgress is true where a migration of it to this layout was begun and not finished.

Migrating a graph from layout 1 to layout 2. StoreLayoutMigration moves a graph on Oracle, Postgres or SQLite from layout 1 to layout 2 in place, by the shared compiler’s migrator, which drivine4j and drivine-python run alike (#765): Migrating a graph from store layout 1 to layout 2 gives the steps. Run it while nothing else uses the graph, with a backup taken first. It is given the provider, and runs on connections of its own from the provider’s pool, never one of a TransactionContextHolder’s transaction: two on Postgres and Oracle, one holding the migration’s lock, so the pool needs room for both. Layout 1 can’t tell which texts are dates or moments, which whole numbers are floats and which texts are bytes, so it is told by declarations, a label’s property and its kind each; declarationsOf(Person) derives them from a node fragment’s fields declared a Date (a moment, datetime), as the object manager knows them (a field a Drivine decorator decorates, or one the class initializes with a Date), under each of its labels, inherited ones too, and declarationsOf(Knows, 'KNOWS') from a relationship fragment’s. A field layout 1 saved in another form than its kind’s is not declared, as the migration would read it as no value of its kind and refuse the graph, and is kept as it is: a @JsonPacked one, saved as a JSON text, and bytes (Uint8Array, Buffer), which 5.0 saved as JSON.stringify writes them. A list of Dates, which TypeScript records as an Array, a date with no time, a float, or a list of either is declared by hand.

const migration = new StoreLayoutMigration(provider); // a PostgresConnectionProvider, say
const declarations = [...declarationsOf(Person), { label: 'Person', property: 'born', kind: 'date' } as Declaration];
const dryRun = await migration.migrate(declarations, { dryRun: true });
const report = await migration.migrate(declarations);

A dry run (dryRun: true) writes nothing, and reports what would change, the values that are no value of their declared kind, the properties whose values all read as one kind (candidates to declare), and the uniqueness constraints’ keys that may collide. A migration ends with a MigrationReport whose status says how: migrated, current or empty (nothing to do), dryRun (a dry run’s), inProgress (a dry run of a graph part way through a migration, which only resuming it goes on with), invalid (a value not of its kind: declare it otherwise, or pass keepInvalid: true), collisions (keys a uniqueness constraint holds once that layout 2 reads as one: correct them with plain SQL and run it again), refused (a graph of another layout, or one changed since its migration began, or resumed, before every row is written, with other declarations or keepInvalid), or failed (the store’s error). One stopped at any moment, or by collisions, is resumed by running it again with the same declarations. It makes no index or constraint, which the application’s schema plan makes at its next start, and leaves the count store unseeded, as the report’s notes say.

Notes:

  • A statement you write yourself is SQL. Parameters are named $name, as in Cypher; a $name in quoted text or a comment, such as the JSON path '$."$t"', is none. A statement that writes and returns rows is a PL/SQL block that hands them back with DBMS_SQL.RETURN_RESULT.
  • A Cypher statement, cypherStatement('MATCH …'), is compiled to SQL over the graph’s tables and gives the rows a graph engine gives: see Cypher on a relational database to start, and Cypher on Oracle and Postgres for how it differs.
  • A predicate you write yourself, for a load or a delete, is SQL over the root’s row n: its props, labels and stamp. A read of the query DSL calls that row n_, and reads n.props, n.labels and n.stamp in your predicate as that row’s. A property of the root may be written as Cypher writes it, n.name = $name (or n.`a name` ), and is read as that property, as text; a property compared with true or false, or with a parameter bound to a boolean (n.open = $open), is compared with the text a JSON boolean is read as. To compare one with a number, read it as a number in SQL. One whose name begins with $, n.`$k` , is read as it is held, under $$k.
  • The query DSL’s conditions, orders, seeks and grouped reads are the shared compiler’s SQL for the Cypher the DSL writes for Neo4j (drivine-cypher-spec#235), as in compiled Cypher: a date is compared by its moment, and text is compared and ordered by its code points (B, a, b), as before. Each statement carries the optimizer hints that SQL asks for. Where it calls one of the graph’s functions (a comparison of a list or a map that holds a null with another, or an order by arithmetic of a property, which may hold a date), a session that may not call it is refused with a DrivineError that says so, where compiled Cypher is compiled again without a comparison’s function.
  • A save is one block and checks the stamp, as on the graph engines. A save turned away by a deadlock (ORA-00060) or a serialization failure (ORA-08177) is run again. Another writer that changes a node in SQL should give it a new stamp: the first sixteen characters of stamp for its properties or labels, the last sixteen for its relationships.
  • Index the id of each class you save: uniquenessConstraint('Person', 'id') makes the unique index a node is found by. Without one, a save reads the table.
  • An index or a constraint is made with the shared compiler’s statements, as drivine4j makes it, byte for byte, so a store either library made has the same indexes. A range index is two indexes, each over the property’s kind and key as store layout 2 holds it: one whatever the label (<graph>_ix2_…), and one over the label’s nodes alone (<graph>_lx2_…), which an equality on the label’s nodes, as the compiler writes it given the store’s indexed properties, is read through. The query DSL’s equality is read through it, and through a uniqueness constraint’s unique index (drivine-cypher-spec#235); a Cypher statement isn’t yet, as it is compiled without them (#753). A uniqueness constraint is a unique index over the label’s nodes that have its properties (<graph>_uq2_…). A value is equal only to one of its kind: 1 and '1' are two keys. It comes with a range index over its properties, which stays when the constraint is dropped; over one property, its unique index stands for the labelled index. An index Drivine 5.0 made, under layout 1’s names, is dropped as its graph is stamped layout 2: see Upgrading to 6.0.
  • Oracle reads an empty string as null, so a comparison with '' in the DSL is written to find a property stored empty.
  • matches takes a regular expression as compiled Cypher’s =~ does, matched against the whole value, in Oracle’s POSIX dialect. A leading (?i) ignores case. A backreference is read as Java reads it only where it is \1 to \8, to a simple group; the shared compiler refuses any other, with why.
  • A vector index is a table of embeddings beside the nodes, kept in step by a trigger, with an Oracle vector index over it by neighbour partitions. The table holds the embeddings of the index’s size; a node written with another size is left out, not refused. loadNearest is approximate through it. With no index made, or one of another size than the vector’s, it measures every node of the label whose embedding is of the vector’s size, and is exact.
  • A full-text index is a table of the indexed text beside the nodes, with an Oracle Text index over it. loadMatching reads words, a "phrase", +must, -not and a prefix*, a word as on Postgres. In a phrase a * is text, as on Neo4j: "of sou*" is the phrase of sou. The index holds what has been committed, so a search doesn’t see its own transaction’s writes. Oracle Text is in the regular Free image, not the slim one; without it, or with no index made, a search counts the words in the text of every node of the label and scores them by BM25, as Postgres does.
  • Each session Drivine opens compares and sorts text by its code points (NLS_COMP = BINARY NLS_SORT = BINARY), as Cypher does, whatever a database or a logon trigger sets: under NLS_COMP = LINGUISTIC NLS_SORT = BINARY_CI, a compiled 'a' = 'A' was true, with no error (drivine-cypher-spec#372). A statement of yours runs in such a session, so its text compares by code points too.
  • Each session Drivine opens makes no adaptive plan (OPTIMIZER_ADAPTIVE_PLANS = FALSE). On tables without statistics, Oracle’s adaptive join plan gave no rows for a read of a graph just written, where the same plan, fixed, gave them all (#331). A statement of yours that relies on an adaptive plan can ask for one with the hint /*+ OPT_PARAM('optimizer_adaptive_plans' 'true') */.
  • Each connection keeps the statements it runs prepared, 30 of them (oracledb’s stmtCacheSize), so a save, the same block each time, is neither sent nor parsed again. A Cypher statement compiled to SQL is not kept: Oracle holds a kept statement’s memory for as long as the driver keeps it, from about 4 MB for a compiled statement to over 20 MB for one that reads a long text, and a few dozen of them ran the instance out of memory (ORA-04036, drivine#396). So it is prepared again each time it runs: about 0.3 ms more for a short statement (Oracle reuses its plan; it doesn’t parse it again from scratch). The object manager’s statements are kept, so where the object manager does what you need, it is the faster way to Oracle.