diff --git a/docs/06-fragments-and-views.md b/docs/06-fragments-and-views.md index 8946a7d0..b104d2e1 100644 --- a/docs/06-fragments-and-views.md +++ b/docs/06-fragments-and-views.md @@ -138,10 +138,11 @@ await gom.load_all(Account, where=refs(Account).email.eq_ignore_case("Ada@Exampl - **The copy.** Every `save`, `create`, `update`, `save_all`, `patch` and `patch_all`, and the save of a view's root and related nodes, writes a lowercased copy of the property beside it, under `__drivine.lower.` (the name it - is stored under, after `GraphProperty`). The database lowercases it, as it lowercases the value a lookup compares - with, so drivine-python, drivine4j and TypeScript's Drivine store and match the same thing. A property with no value - has no copy. A load doesn't read it, and a flat `PropertyBag` never holds it. The copy is no part of whether a save - changed the node, so a save that only fills one in keeps the node's stamp. Cypher you send yourself doesn't: see + is stored under, after `GraphProperty`); on a SQL store, which holds a property named `$mail` as `$$mail`, the copy + is still `__drivine.lower.$mail`. The database lowercases it, as it lowercases the value a lookup compares with, so + drivine-python, drivine4j and TypeScript's Drivine store and match the same thing. A property with no value has no + copy. A load doesn't read it, and a flat `PropertyBag` never holds it. The copy is no part of whether a save changed + the node, so a save that only fills one in keeps the node's stamp. Cypher you send yourself doesn't: see [below](#cypher-of-your-own). - **The index.** `RangeIndex(ignore_case=True)`, `Unique(ignore_case=True)`, `range_index(label, property, ignore_case=True)` and `uniqueness_constraint(label, property, ignore_case=True)` are made over the copy, under their @@ -152,6 +153,9 @@ await gom.load_all(Account, where=refs(Account).email.eq_ignore_case("Ada@Exampl - **Filling it in.** Ensuring an item that ignores case first fills the copy in on every node of the label that lacks it, 10,000 nodes a statement, and records that every node has it: on the store's `DrivineStore` node on the graph engines, in the graph's catalog on Oracle and Postgres. An item made anew, or recreated, fills the copies in again. + On Oracle, Postgres and SQLite every ensure also fills in again the copy of a property named with a `$`, though + recorded: an earlier version wrote none, or wrote it under the held name, `__drivine.lower.$$mail`, which no lookup + reads, so a node it saved is missed by a lookup until an ensure has run. - **The lookup.** Once the copy is recorded, `eq_ignore_case` and `contains_ignore_case` on the field compare with the copy: in a load, a count, a `delete_all`, a grouped read and a patch's condition, on the root's own fields. Until then, and for an empty value or a related node's field, they lowercase the property, as for any field: the same diff --git a/drivine/backend/oracle/oracle_save_builder.py b/drivine/backend/oracle/oracle_save_builder.py index 75ca2a3b..c0161fa2 100644 --- a/drivine/backend/oracle/oracle_save_builder.py +++ b/drivine/backend/oracle/oracle_save_builder.py @@ -604,9 +604,10 @@ def prelude(graph: OracleGraph, declarations: Sequence[str], lowers: bool = Fals def _lower_node(nodes: str) -> str: """ - `lower_node`: writes on the node the lowercased copy of each property `p_keys`, a JSON array, names, from what it - holds, and removes the copy of one that holds nothing, which an empty text is on Oracle. Oracle lowercases it, as it - lowercases what a lookup compares the copy with: see lower_copies. It is called once a write's change is told, so + `lower_node`: writes on the node the lowercased copy of each property `p_keys`, a JSON array, names as the node + holds it (see held_key), from what it holds, under the user's name (`__drivine.lower.$mail` for `$$mail`), and + removes the copy of one that holds nothing, which an empty text is on Oracle. Oracle lowercases it, as it lowercases + what a lookup compares the copy with: see lower_copies. It is called once a write's change is told, so the copies are no part of it. The copy is read and written as a CLOB, so a text past what a VARCHAR2 holds has its copy too. """ @@ -617,17 +618,20 @@ def _lower_node(nodes: str) -> str: o JSON_OBJECT_T; lowered JSON_ARRAY_T := JSON_ARRAY_T.parse(p_keys); k VARCHAR2(4000); + c VARCHAR2(4000); v CLOB; BEGIN SELECT props INTO held FROM {nodes} WHERE nid = p; o := JSON_OBJECT_T(held); FOR i IN 0 .. lowered.get_size - 1 LOOP k := lowered.get_string(i); + -- k is the property as the node holds it; its copy is named for the user's name, $mail for $$mail. + c := '{lower_copies.PREFIX}' || CASE WHEN SUBSTR(k, 1, 2) = '$$' THEN SUBSTR(k, 2) ELSE k END; v := NULL; IF o.has(k) AND NOT o.get(k).is_null THEN v := LOWER(o.get_clob(k)); END IF; -- Oracle keeps an empty text as null, so an empty property has no copy. - IF v IS NULL OR LENGTH(v) = 0 THEN o.remove('{lower_copies.PREFIX}' || k); - ELSE o.put('{lower_copies.PREFIX}' || k, v); END IF; + IF v IS NULL OR LENGTH(v) = 0 THEN o.remove(c); + ELSE o.put(c, v); END IF; END LOOP; -- An object type's methods are PL/SQL's: called in SQL, they are refused (ORA-40573). held := o.to_json; diff --git a/drivine/backend/oracle/oracle_schema_grammar.py b/drivine/backend/oracle/oracle_schema_grammar.py index f6388c2b..6607ec95 100644 --- a/drivine/backend/oracle/oracle_schema_grammar.py +++ b/drivine/backend/oracle/oracle_schema_grammar.py @@ -23,6 +23,7 @@ catalog_properties, catalog_record, ) +from drivine.backend.sql.value_layout import held_key from drivine.model import lower_copies from drivine.schema.full_text_index_spec import FullTextIndexSpec from drivine.schema.lower_copy_statements import LOWER_COPY_KIND, LowerCopyStatements, Recording, catalog_entries @@ -165,8 +166,10 @@ def _lower_copies(graph: OracleGraph) -> LowerCopyStatements: """ def fill(label: str, property: str, batch: int) -> str: + # The copy is named for the user's name, and the value read where the node holds it, $$mail for $mail + # (drivine-cypher-spec#355). path = f"'$.{drivine4j_step(lower_copies.of(property))}'" - value = f"JSON_VALUE(n.props, '$.{drivine4j_step(property)}' RETURNING CLOB)" + value = f"JSON_VALUE(n.props, '$.{drivine4j_step(held_key(property))}' RETURNING CLOB)" copy = f"JSON_VALUE(n.props, {path} RETURNING CLOB)" return f"""DECLARE v_written NUMBER; diff --git a/drivine/backend/postgres/postgres_schema_grammar.py b/drivine/backend/postgres/postgres_schema_grammar.py index fc1b9228..6136e283 100644 --- a/drivine/backend/postgres/postgres_schema_grammar.py +++ b/drivine/backend/postgres/postgres_schema_grammar.py @@ -17,6 +17,7 @@ catalog_record, ) from drivine.backend.sql.sql_graph import sql_text +from drivine.backend.sql.value_layout import held_key from drivine.model import lower_copies from drivine.schema.full_text_index_spec import FullTextIndexSpec from drivine.schema.lower_copy_statements import LOWER_COPY_KIND, LowerCopyStatements, Recording, catalog_entries @@ -80,18 +81,21 @@ def _lower_copies(graph: PostgresGraph) -> LowerCopyStatements: """ def fill(label: str, property: str, batch: int) -> str: + # The copy is named for the user's name, and the value read where the node holds it, $$mail for $mail + # (drivine-cypher-spec#355). copy_key = sql_text(lower_copies.of(property)) + held = held_key(property) return "\n".join( [ "WITH written AS (", f" UPDATE {graph.nodes} n", - f" SET props = CASE WHEN n.props ->> {sql_text(property)} IS NULL THEN n.props - {copy_key}", + f" SET props = CASE WHEN n.props ->> {sql_text(held)} IS NULL THEN n.props - {copy_key}", f" ELSE n.props || jsonb_build_object({copy_key}, lower(n.props ->> " - f"{sql_text(property)})) END", + f"{sql_text(held)})) END", " WHERE n.nid IN (", f" SELECT m.nid FROM {graph.nodes} m", f" WHERE {has_labels('m', [label])} AND {text_of('m', lower_copies.of(property))} IS DISTINCT " - f"FROM lower({text_of('m', property)})", + f"FROM lower({text_of('m', held)})", f" LIMIT {batch})", " RETURNING 1)", 'SELECT count(*) AS "written" FROM written', diff --git a/drivine/backend/sql/value_layout.py b/drivine/backend/sql/value_layout.py index 428defba..632abd03 100644 --- a/drivine/backend/sql/value_layout.py +++ b/drivine/backend/sql/value_layout.py @@ -59,6 +59,16 @@ def held_key(name: str) -> str: return f"${name}" if name.startswith("$") else name +def user_key(held: str) -> str: + """ + The user's name of a property the store holds as `held`, undoing held_key: `$mail` for `$$mail`. A name held with a + `$` begins with `$$`; one that begins with a single `$` is no held name, and is given back as it is. The lowercased + copy of a property is named for the user's name (lower_copies.of), as each lookup and the ignore-case index read it + (liberation-data/drivine-cypher-spec#355). + """ + return held[1:] if held.startswith("$$") else held + + def write(value: Any, store: SqlStore) -> Any: """`value` as a save writes it on `store` (see the module): as it is, or the module's text of it, `Held`.""" made = prepared(value) diff --git a/drivine/backend/sqlite/sqlite_extension.py b/drivine/backend/sqlite/sqlite_extension.py index 7a2de2ba..bacbd868 100644 --- a/drivine/backend/sqlite/sqlite_extension.py +++ b/drivine/backend/sqlite/sqlite_extension.py @@ -26,7 +26,7 @@ ENTRY = "sqlite3_drivinecypher_init" """The extension's entry point in the module's library.""" -HOST_VERSION = 2 +HOST_VERSION = 3 """The version of the host functions' forms compiled SQL expects: the module's `SqliteFunctions.HOST_VERSION`.""" PACKAGE = "drivine-cypher-compiler" diff --git a/drivine/backend/sqlite/sqlite_functions.py b/drivine/backend/sqlite/sqlite_functions.py index b70346c1..52abbf0f 100644 --- a/drivine/backend/sqlite/sqlite_functions.py +++ b/drivine/backend/sqlite/sqlite_functions.py @@ -31,6 +31,7 @@ import apsw +from drivine.backend.sql.value_layout import held_key from drivine.backend.sqlite import sqlite_cypher_functions, sqlite_extension, sqlite_graph from drivine.backend.sqlite.sqlite_arguments import text as text_of_argument from drivine.backend.sqlite.sqlite_graph import SqliteGraph, has_label, path, text_of @@ -136,14 +137,17 @@ def _lower_copies( if graph is None or label is None or property is None: raise ValueError("drivine_lower_copies names a graph, a label and a property.") nodes = SqliteGraph(graph).nodes + # The copy is named for the user's name, and the value read where the node holds it, $$mail for $mail + # (drivine-cypher-spec#355). + held = held_key(property) copy = lower_copies.of(property) def lowered(alias: str) -> str: - return f"{sqlite_graph.LOWER}({text_of(alias, property)})" + return f"{sqlite_graph.LOWER}({text_of(alias, held)})" connection.execute( f"UPDATE {nodes} AS n\n" - f"SET props = CASE WHEN {text_of('n', property)} IS NULL THEN json_remove(n.props, {path(copy)}) " + f"SET props = CASE WHEN {text_of('n', held)} IS NULL THEN json_remove(n.props, {path(copy)}) " f"ELSE json_set(n.props, {path(copy)}, {lowered('n')}) END\n" "WHERE n.nid IN (\n" f" SELECT m.nid FROM {nodes} m\n" diff --git a/drivine/backend/sqlite/sqlite_plan_writer.py b/drivine/backend/sqlite/sqlite_plan_writer.py index c2adfbc7..f24ac789 100644 --- a/drivine/backend/sqlite/sqlite_plan_writer.py +++ b/drivine/backend/sqlite/sqlite_plan_writer.py @@ -8,6 +8,7 @@ import apsw +from drivine.backend.sql.value_layout import user_key from drivine.backend.sql.write_plan import WriteReturns from drivine.backend.sqlite import exact_json from drivine.backend.sqlite.sqlite_graph import SqliteGraph, has_labels @@ -584,20 +585,23 @@ def _set_and_unset(o: dict[str, Any], step: dict[str, Any]) -> None: def _lowered(o: dict[str, Any], keys: Any) -> dict[str, Any]: """ - `o` with the lowercased copy of each property `keys` names, from what `o` holds, and without the copy of one that - holds nothing: see lower_copies. It is lowercased as the lower function lowercases what a lookup compares the copy - with. `o` itself where `keys` names none. + `o` with the lowercased copy of each property `keys` names as the node holds it (see held_key), from what `o` + holds, and without the copy of one that holds nothing: see lower_copies. The copy is named for the user's name, + `__drivine.lower.$mail` for `$$mail` (see user_key). It is lowercased as the lower function lowercases what a + lookup compares the copy with. `o` itself where `keys` names none. """ names = _strings(keys) if not names: return o copied = dict(o) for key in names: + # Each key is the property as the node holds it; its copy is named for the user's name + # (drivine-cypher-spec#355). value = copied.get(key) if value is None: - copied.pop(lower_copies.of(key), None) + copied.pop(lower_copies.of(user_key(key)), None) else: - copied[lower_copies.of(key)] = _as_text(value).lower() + copied[lower_copies.of(user_key(key))] = _as_text(value).lower() return copied diff --git a/drivine/model/lower_copies.py b/drivine/model/lower_copies.py index c9fd27ff..1357af87 100644 --- a/drivine/model/lower_copies.py +++ b/drivine/model/lower_copies.py @@ -23,7 +23,11 @@ def of(property: str) -> str: - """The property the copy of `property`, a stored name, is stored under.""" + """ + The property the copy of `property`, a stored name, is stored under. The name is the one after `GraphProperty`, not + as a SQL store's layout holds it: the copy of `$mail`, held as `$$mail`, is `__drivine.lower.$mail` + (drivine-cypher-spec#355). + """ return f"{PREFIX}{property}" diff --git a/drivine/schema/lower_copy_catalog.py b/drivine/schema/lower_copy_catalog.py index 5ef24074..3bfaf5d1 100644 --- a/drivine/schema/lower_copy_catalog.py +++ b/drivine/schema/lower_copy_catalog.py @@ -9,7 +9,12 @@ from drivine.drivine_error import DrivineError from drivine.schema.full_text_index_spec import FullTextIndexSpec -from drivine.schema.lower_copy_statements import LOWER_COPY_BATCH, LowerCopyStatements, column_of +from drivine.schema.lower_copy_statements import ( + CYPHER_LOWER_COPIES, + LOWER_COPY_BATCH, + LowerCopyStatements, + column_of, +) from drivine.schema.range_index_spec import RangeIndexSpec from drivine.schema.schema_specs import item_name, lowercased from drivine.schema.uniqueness_constraint_spec import UniquenessConstraintSpec @@ -84,7 +89,7 @@ async def fill_in(self, label: str, properties: Sequence[str], again: bool) -> N if not properties: return stored: set[tuple[str, str]] = set() if again else await self._stored() - for property in [it for it in properties if again or (label, it) not in stored]: + for property in [it for it in properties if again or self._healed(it) or (label, it) not in stored]: filled = 0 while True: rows = await self._run(self._statements.fill(label, property, self._batch), None) @@ -98,7 +103,9 @@ async def fill_in(self, label: str, properties: Sequence[str], again: bool) -> N recording = self._statements.record(label, property) await self._run(recording.statement, recording.bindings) self._recorded.add((label, property)) - logger.info( + # A $-named property is filled in again on every ensure (see _healed): one that wrote nothing is no news. + logger.log( + logging.DEBUG if filled == 0 and self._healed(property) else logging.INFO, "Filled in the lowercased copy of %s.%s on %d node(s), and recorded that every node has it", label, property, @@ -106,8 +113,20 @@ async def fill_in(self, label: str, properties: Sequence[str], again: bool) -> N ) async def stored(self) -> set[tuple[str, str]]: - """The lowercased copies the store records as filled in, each `(label, property)`, read now.""" - return await self._stored() + """ + The lowercased copies the store records as filled in, each `(label, property)`, read now, but for those to fill + in again though recorded (see _healed): the schema planner's `ReadLowerCopies`, which fills in only what this + leaves out. A lookup reads the whole record (see filled_in). + """ + return {it for it in await self._stored() if not self._healed(it[1])} + + def _healed(self, property: str) -> bool: + """ + Whether `property` is filled in again though recorded: on a SQL store, one named with a `$`. One saved before + drivine-cypher-spec#355 held its copy under the escaped name, `__drivine.lower.$$mail`, which no lookup reads, + or held none; the fill writes only the nodes whose copy is out of step. The graph engines always named it right. + """ + return self._statements is not CYPHER_LOWER_COPIES and property.startswith("$") async def _stored(self) -> set[tuple[str, str]]: """What the store records, read now.""" diff --git a/drivine/sync/schema/lower_copy_catalog.py b/drivine/sync/schema/lower_copy_catalog.py index 13a78144..0782fdcf 100644 --- a/drivine/sync/schema/lower_copy_catalog.py +++ b/drivine/sync/schema/lower_copy_catalog.py @@ -11,7 +11,12 @@ from drivine.drivine_error import DrivineError from drivine.schema.full_text_index_spec import FullTextIndexSpec -from drivine.schema.lower_copy_statements import LOWER_COPY_BATCH, LowerCopyStatements, column_of +from drivine.schema.lower_copy_statements import ( + CYPHER_LOWER_COPIES, + LOWER_COPY_BATCH, + LowerCopyStatements, + column_of, +) from drivine.schema.range_index_spec import RangeIndexSpec from drivine.schema.schema_specs import item_name, lowercased from drivine.schema.uniqueness_constraint_spec import UniquenessConstraintSpec @@ -86,7 +91,7 @@ def fill_in(self, label: str, properties: Sequence[str], again: bool) -> None: if not properties: return stored: set[tuple[str, str]] = set() if again else self._stored() - for property in [it for it in properties if again or (label, it) not in stored]: + for property in [it for it in properties if again or self._healed(it) or (label, it) not in stored]: filled = 0 while True: rows = self._run(self._statements.fill(label, property, self._batch), None) @@ -100,7 +105,9 @@ def fill_in(self, label: str, properties: Sequence[str], again: bool) -> None: recording = self._statements.record(label, property) self._run(recording.statement, recording.bindings) self._recorded.add((label, property)) - logger.info( + # A $-named property is filled in again on every ensure (see _healed): one that wrote nothing is no news. + logger.log( + logging.DEBUG if filled == 0 and self._healed(property) else logging.INFO, "Filled in the lowercased copy of %s.%s on %d node(s), and recorded that every node has it", label, property, @@ -108,8 +115,20 @@ def fill_in(self, label: str, properties: Sequence[str], again: bool) -> None: ) def stored(self) -> set[tuple[str, str]]: - """The lowercased copies the store records as filled in, each `(label, property)`, read now.""" - return self._stored() + """ + The lowercased copies the store records as filled in, each `(label, property)`, read now, but for those to fill + in again though recorded (see _healed): the schema planner's `ReadLowerCopies`, which fills in only what this + leaves out. A lookup reads the whole record (see filled_in). + """ + return {it for it in self._stored() if not self._healed(it[1])} + + def _healed(self, property: str) -> bool: + """ + Whether `property` is filled in again though recorded: on a SQL store, one named with a `$`. One saved before + drivine-cypher-spec#355 held its copy under the escaped name, `__drivine.lower.$$mail`, which no lookup reads, + or held none; the fill writes only the nodes whose copy is out of step. The graph engines always named it right. + """ + return self._statements is not CYPHER_LOWER_COPIES and property.startswith("$") def _stored(self) -> set[tuple[str, str]]: """What the store records, read now.""" diff --git a/pyproject.toml b/pyproject.toml index a63463cf..7bfe980b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,25 +32,25 @@ falkordb = [ # Full-text search on a graph engine is written by the shared compiler too, which the graph engines' extras don't # install, as it has no wheel for every platform they run on (an Intel Mac, musl Linux): `pip install # "drivine[neo4j,compiler]"` where it has one. Pinned as the SQL stores' extras pin it. -compiler = ["drivine-cypher-compiler==0.54.4"] +compiler = ["drivine-cypher-compiler==0.56.0"] # Each SQL store compiles Cypher with the shared compiler, drivine-cypher-compiler, a native library with a wheel for # macOS on Apple Silicon, Linux with glibc (x86_64, aarch64) and Windows x64: in the extras, so `pip install drivine` # installs anywhere and the graph engines work where it has no wheel (an Intel Mac, musl Linux). Pinned exactly, to the # compiler of the Cypher spec tests/cypher is a copy of. oracle = [ "oracledb>=3.0", - "drivine-cypher-compiler==0.54.4", + "drivine-cypher-compiler==0.56.0", ] postgres = [ "psycopg[binary]>=3.2", "psycopg-pool>=3.2", - "drivine-cypher-compiler==0.54.4", + "drivine-cypher-compiler==0.56.0", ] # SQLite is apsw's, which bundles its own SQLite: 3.53.2 or later, which writes a float as text to 17 significant # digits as compiled Cypher needs (3.53.0 and 3.53.1 still write 15), whatever SQLite Python was built with (#376). sqlite = [ "apsw>=3.53.2", - "drivine-cypher-compiler==0.54.4", + "drivine-cypher-compiler==0.56.0", ] [project.entry-points.pytest11] diff --git a/tests/cypher/README.md b/tests/cypher/README.md index 8d38273e..39931aba 100644 --- a/tests/cypher/README.md +++ b/tests/cypher/README.md @@ -13,7 +13,7 @@ These files say what a statement in Drivine's flavour of Cypher gives on each st - `store.yaml`: the store layout's DDL: the tables, the probe that finds them made, and each index and constraint as each store makes, drops and lists it, for the graph `drivine` and a set of schema specs, with a read for each index that the compiler must answer from it. Read with no store. See [The store layout](#the-store-layout). It also holds the store's schema: how each store's listings are read back, whether an item is a spec's and in its shape, and on a SQL store of which form, what each store can do, and what its errors say. See [The store's schema](#the-stores-schema). - `marker.yaml`: the schema marker (`_DrivineSchema`) and the stamps: the statements each store reads and writes the marker and the store's stamp (`DrivineStore`) with, the marker's inventory as it is written and read back, the version token, and the form of the stamp each node carries. Read with no store. See [The schema marker and the stamps](#the-schema-marker-and-the-stamps). - `migrate.yaml`: a store's layout migrated, from layout 1 to layout 2: each row of a node's or a relationship's properties as layout 1 held it, on each SQL store, rewritten as layout 2 holds it, under what the migration is told of the properties' kinds. Read with no store. See [Migrating a store's layout](#migrating-a-stores-layout). -- `bulk.yaml`: a bulk import of nodes and relationships into a SQL store: the statements a library runs, in order, in one transaction, for the graph `drivine`. Read with no store. See [Importing a graph in bulk](#importing-a-graph-in-bulk). +- `bulk.yaml`: a bulk import of nodes and relationships into a SQL store: the statements a library runs, in order, in one transaction, for the graph `drivine`, and the JSON entry's request for them (`json`). Read with no store. See [Importing a graph in bulk](#importing-a-graph-in-bulk). - `plans.yaml`: the schema plan: what a schema manager runs on each store, round by round, for an enforce, a recreate, an ensure or a remove, what the store answers, and what the manager reports, its log lines among it. Read with no store. See [The schema plan](#the-schema-plan). - `declarations.yaml`: what each library's schema declarations give the schema planner: the catalogs of a request, and the items ensured at runtime, for each of a set of declarations. Read with no store. See [The schema declarations](#the-schema-declarations). - `host.yaml`: what each library's own code does with the values compiled SQL hands it: the functions it registers on SQLite, and how it reads a column of a statement's rows. Read with no store. See [Host functions and readers](#host-functions-and-readers). @@ -71,6 +71,8 @@ On Neo4j a statement runs in the database's default language, Cypher 25 on Neo4j - A temporal value made of a list, a number or a truth value fails by name on the SQL stores, where it gave null, as Neo4j fails it (liberation-data/drivine-cypher-spec#331): as the statement compiles where it is written or given, so never null, and as it runs where it is read, a variable's, a function's or a `CASE`'s, which gives null where it is null, as Neo4j's does; a truth value a comparison makes, `date(n.x > 1)`, is refused as it compiles, though it may be null. Neo4j fails only a row that reaches the call, so a statement that gives no rows is refused on the SQL stores where Neo4j gives none. - `+` of a truth value and a number, a truth value, a map or a temporal value, or of a map and a number, gave null on the SQL stores, where Neo4j refuses it (liberation-data/drivine-cypher-spec#341): it is refused as the statement compiles where the compiler knows both kinds. A truth value put together with a text is its text, `'a' + true` is `atrue`, as in Neo4j, where the SQL stores gave null. - A map beside a text or a temporal value in `+`, `*` or `/` of a temporal value other than a duration, and `NOT` of a parameter given a value that is no truth value or of a text put together, gave null on the SQL stores, where Neo4j refuses each as it plans the statement (liberation-data/drivine-cypher-spec#345): each is refused as the statement compiles. A truth value read as the statement runs (a property, a variable or an item) beside a number the statement makes or gives, in `+`, `-`, `*` or `/`, fails the statement there, where it gave null, as Neo4j fails it, by one test of the side read: `n.flag + 1`, `UNWIND $l AS b RETURN b + 1`. Beside a number the statement makes that is null as it runs (`n.flag + toFloat(n.missing)`), it is null, as in Neo4j. Beside a side of a kind left open too (`n.flag + n.n`), a map or a temporal value (`n.flag + date('2024-01-01')`), or worked out rather than read (`head($l) + 1`), it still gives null on the SQL stores, where Neo4j fails; so does a text, a list or a map read as the statement runs in `-`, `*` or `/`, and a truth value in `%` or `^`. A test of each side's kind in every `+` (#341) grew a sum of sums at every level. +- A temporal value the statement makes or a parameter gives, and a parameter given an integer, a text or a map, read as a condition (in a `WHERE`, `AND`, `OR`, `XOR` or `NOT`, a searched `CASE`'s `WHEN`, or a list comprehension's or a quantifier's `WHERE`, carried by a `WITH`, an `UNWIND`, a list's item or a map's entry) gave null on the SQL stores, or kept no row, where Neo4j refuses the statement as it plans it, over no rows too (liberation-data/drivine-cypher-spec#451): each is refused as the statement compiles. A temporal value beside a null written or read in a `coalesce()`, a `CASE` or a list, or an entry of a map taken from a list of maps, which Neo4j types as any value, as it does a sum of one (it refuses a difference, a product or a quotient of one), and a parameter given a float, which Neo4j fails only as a row reads it, a list, which it reads by whether it holds an item, a truth value or null, are compiled as before. +- A value whose kind only the row tells, read as a condition, an index, a key or a list where it is of another kind than that takes, is null on the SQL stores in a statement that only reads, where Neo4j fails it, as a SQL engine orders conditions as it likes and a failure there would fail statements Neo4j runs (liberation-data/drivine-cypher-spec#453, #458). A statement that writes fails there instead, before it writes anything, as Neo4j fails it (#493): a condition that turns out a number, a text, a list or a temporal value; an index of what is no list, or that is no whole number; a text key of what is no map, or of a temporal value but for a field of its kind written in the statement (#484); a node, a relationship, a map the statement makes or gives, or `properties()`, read as a list. A row a condition joined by `AND` at the top of a `WHERE` is false for fails nothing, whichever is written first, nor does a row a pattern finds nothing for, the properties it is given among them; any other such value read fails the statement, even beside a condition that decides, as Neo4j reads `AND`, `OR` and `XOR` in the order its plan gives. A `CASE`'s results and conditions, `coalesce()`'s arguments and a quantifier's items are read only as far as Neo4j reads them. A map or a temporal value only the row tells the kind of is read as a list of it, as Neo4j reads it, in a statement that writes. - A temporal value given at an offset with seconds, a parameter or a value a save writes, is refused by name on the SQL stores, where Neo4j holds it, as the store holds an offset to the minute (see "A time" in [Values in the store](#values-in-the-store)): `{"$temporal": "DATE_TIME", "text": "1971-01-01T00:00:00-00:44:30"}`, or a JVM `OffsetDateTime` or `ZonedDateTime` there, as java.time writes a zone's local mean time (`Africa/Monrovia` before 1972), is refused with "A value given as a DATE_TIME isn't one: 1971-01-01T00:00:00-00:44:30 (the store holds an offset to the minute)." So is any other value given as a temporal value whose text is no value of its kind, `{"$temporal": "DATE", "text": "2024-13-01"}`. Each was bound, or saved, as its text, equal to no temporal value (liberation-data/drivine-cypher-spec#357). `host.yaml`'s "Values a save writes" pins the refusal; the spec's statement files take no parameter given as a temporal value, so a statement's is pinned by the module's tests. - Quote every string. A YAML 1.1 parser, such as SnakeYAML or PyYAML, reads a bare `y`, `yes`, `no` or `on` as a boolean. - `writes.yaml` binds and expects a whole number beyond 2^53. A library whose language reads YAML numbers as doubles skips those steps, named in its own runner. Otherwise a library skips nothing: a store that differs says so with `except` here. @@ -84,6 +86,7 @@ In its rows: - `{$t: "node", labels: […], properties: {…}}` is a node, with its labels in any order; - `{$t: "relationship", type: "…", properties: {…}}` is a relationship; - `{$t: "path", nodes: […], relationships: […]}` is a path, its nodes and relationships in the order it walks them; +- `{$t: "date", v: "2024-02-29"}` is a temporal value, of the kind `$t` names, `date`, `localtime`, `time`, `localdatetime`, `datetime` or `duration`, with its canonical text `v`, as layout 2 holds it: a graph engine's driver gives a temporal value, and a SQL store's typed read gives one from its tag, read with the module's `ValueLayout.readValue(value, typed = true)` (or `read` typed), not its text (#483). A text, as `"2024-02-29"` is, stays a text; - `{$map: {…}}` is the map it holds, for a map with a `$t` key of its own. On a SQL store, the compiler gives the columns, and compiled typed (`typed`) it tags each node and relationship as above in the columns that hold them: see the compiler's README. It is opt-in, and untyped every statement compiles as before. @@ -150,7 +153,7 @@ cases: | Key | What it is | |---|---| -| `tables` | What makes each SQL store's tables, base indexes and functions (`ddl`, and Oracle's `functions`), each statement safe to run again, and how a library finds them made. On Postgres, `ensuring` is one block: the probe of the node table's comment, which holds the version token (`drivine:12`), the graph's advisory lock, and the `ddl`. On Oracle, `ensuring` probes the property graph's `doc` property and each function, and makes what is missing, or a function not of its version. A function whose compile fails (`ORA-24344`, or `ORA-04021` and `ORA-04031`, a busy library cache or a short shared pool) is compiled again after 0.5 s, then 1 s, and after its third try the block fails with `ORA-20818`, naming the function and what `user_errors` says of it (liberation-data/drivine#818). On SQLite, `made` counts what of the `ddl` is there, or is -1 for tables made without `AUTOINCREMENT`, and `file` names the database's file. | +| `tables` | What makes each SQL store's tables, base indexes and functions (`ddl`, and Oracle's `functions`), each statement safe to run again, and how a library finds them made. On Postgres, `ensuring` is one block: the probe of the node table's comment, which holds the version token (`drivine:16`), the graph's advisory lock, and the `ddl`. On Oracle, `ensuring` probes the property graph's `doc` property and each function, and makes what is missing, or a function not of its version. A function whose compile fails (`ORA-24344`, or `ORA-04021` and `ORA-04031`, a busy library cache or a short shared pool) is compiled again after 0.5 s, then 1 s, and after its third try the block fails with `ORA-20818`, naming the function and what `user_errors` says of it (liberation-data/drivine#818). On SQLite, `made` counts what of the `ddl` is there, or is -1 for tables made without `AUTOINCREMENT`, and `file` names the database's file. | | `catalog` | Each store's queries that list its indexes of each kind and its constraints; on a SQL store, the statements that set and take away the `aliases` of the record of `item`; and Oracle's `labelled`, the labelled indexes a library tells the compiler of as `indexedProperties`. On a SQL store a listing of range indexes or of constraints, and on Postgres and Oracle one of vector or full-text indexes, gives, after the records, a row for each object under a name Drivine gives that kind's objects (see [Forms](#the-stores-schema)). | | `names` | The name a SQL store gives an object of `kind` made for `parts`, a label and properties, for a `graph`: `___`, where `layout` is the store layout the object holds values in, `2` (see [Values in the store](#values-in-the-store)). `readable` is the parts' ASCII letters and digits run together, cut to at most 40 and to what leaves room, within the store's longest name (63 on Postgres and SQLite, 128 on Oracle), for the rest and a `_t`. `hash` is Java's `String.hashCode` of the parts joined by U+0000, over their UTF-16 code units, as `Integer.toHexString` writes it: unsigned, in lower case, with no leading zeros (`drivine_ix2_name_337a8b`). | | `refusals` | Why a store refuses a graph's name, or null where it takes it. A graph's name is at most the store's longest name less 16 (47 on Postgres and SQLite, 112 on Oracle): the longest a name adds is `_uq2__`, a hash of 8 with nothing readable, and the `_t`, `_i` or `_r` of an object made beside it, so each fits. | @@ -196,7 +199,7 @@ The canonical text `v`: - **A local time** is `hh:mm:ss`, the seconds always written, then where the second has a fraction a point and the fewest of three, six or nine digits that hold it, as Java's `Instant.toString` writes one: `10:30:00`, `10:30:00.500`, `10:30:00.000001`, `10:30:00.123456789`. - **A time** is a local time and its offset: `Z` for an offset of zero, however it was written (`+00:00`, `-0000`), else `±hh:mm`. Offsets run from -18:00 to +18:00. A named zone (`[Europe/Paris]`) is not held: a library writes the offset it has at that moment. An offset with seconds (`-00:44:30`) is not held either: a value given at one is refused by name (see [Values](#values)). - **A local moment** is a date, `T`, and a local time; **a moment** a date, `T`, and a time. -- **A duration** is its months, days and seconds, kept apart as Cypher keeps them (`P1D` is not `PT24H`), written as Neo4j writes one: `P`, then the whole years and the months left of the months, then the days, then `T` and the whole hours, the whole minutes and the seconds left, with their fraction and no trailing zeros, of the seconds; each part left out where it is 0, each signed on its own (`PT-1H-30M`), and `PT0S` where all are 0. A week is 7 days; a fraction of a month is 30.436875 days, and a fraction of a day 86,400 seconds, carried to the part below. +- **A duration** is its months, days and seconds, kept apart as Cypher keeps them (`P1D` is not `PT24H`), written as Neo4j writes one: `P`, then the whole years and the months left of the months, then the days, then `T` and the whole hours, the whole minutes and the seconds left, with their fraction and no trailing zeros, of the seconds; each part left out where it is 0, each signed on its own (`PT-1H-30M`), and `PT0S` where all are 0. A week is 7 days; a fraction of a month is 30.436875 days, and a fraction of a day 86,400 seconds, carried to the part below. As in Neo4j, a duration's seconds are written to nine places at most, and its length in whole seconds, its fraction left out (a negative duration's seconds floored), a month as 2,629,746 of them and a day as 86,400, lies within a 64-bit integer, each product and sum on the way too, the days' added to the months' before the seconds: a duration text the statement writes past either is refused, and one it works out past the nanosecond fails as it runs (#491); one made from a map of numbers the statement writes past the length is refused too, and one made past it from a map of fields worked out, of a text worked out, or by arithmetic fails as it runs, as Neo4j fails it as it makes the duration, as does one scaled whose whole seconds or nanoseconds of the second, which Neo4j scales each on their own, pass a 64-bit integer (#498). The sort key `s` is worked out of `v` alone, never of a store's timestamp, which holds neither every year nor nanoseconds; so every writer's `s` of a value is the same. Within one `$t`, two values order as their `s` do as text, under any collation, as Neo4j orders them. Values of two kinds have no order, and neither have durations. @@ -360,7 +363,7 @@ nodeStamps: {property: "__drivine.stamp", token: 16, separator: ":", neverStampe | `inventory` | A `record` of keys, the runtime ones and the stale ones; its `items`, as every store but Oracle keeps them; and what is `read` back from them. | | `reads` | A stored text as a store gives it back, or null where no marker or no `items` came back, and what is `read` from it: null for no inventory known, which is not an empty one. `oracle` is what Oracle reads, where it differs, its mark taken off first. | | `versions` | The version tokens of an owner's catalogs, null for one that sets none, and the token the owner records: null where none sets one. | -| `storeStamp` | The stamp's label, the property it is merged on and that property's value, its constraint, and what `assignIfAbsent` binds: `storeId`, a new UUID's text, `assignedAt`, the moment as ISO-8601 text in UTC, as Java's `Instant.toString` writes it (`2026-11-10T05:00:00.123456Z`: the fraction of a second in three, six or nine digits, the fewest that hold it, and none for a whole second), and not a number, as `readStamps` orders by it, `engine`, the store's name as the stamp records it, and `layout`, the store layout the library holds values in: 2 on a SQL store, 1 on a graph engine, whose stamp's statements don't write it. Each store's `engine`, as the stamp records it, its `layout`, its `prepare`, run first as the marker's is, and statements: `assignIfAbsent` makes the stamp where there is none; `readStamps` reads every stamp as a map `{id, assignedAt, layout}`, the oldest first, tie-broken by id, and a library takes the first, so every reader takes the same one; `foreignNodes` gives a row where the graph holds a node other than the stamp and the schema marker; `restampLayout` sets the stamp's `layout`, binding `restampParameters`, only while it holds none, in one statement; and `layoutObjects` lists the indexes, tables and triggers Drivine may have made for the graph, each `{name, type}`. The last two are null on a graph engine. See `storeLayout`. | +| `storeStamp` | The stamp's label, the property it is merged on and that property's value, its constraint, and what `assignIfAbsent` binds: `storeId`, a new UUID's text, `assignedAt`, the moment as ISO-8601 text in UTC, as Java's `Instant.toString` writes it (`2026-11-10T05:00:00.123456Z`: the fraction of a second in three, six or nine digits, the fewest that hold it, and none for a whole second), and not a number, as `readStamps` orders by it, `engine`, the store's name as the stamp records it, and `layout`, the store layout the library holds values in: 2 on a SQL store, 1 on a graph engine, whose stamp's statements don't write it. Each store's `engine`, as the stamp records it, its `layout`, its `prepare`, run first as the marker's is, and statements: `assignIfAbsent` makes the stamp where there is none; `readStamps` reads every stamp as a map `{id, assignedAt, layout}`, the oldest first, tie-broken by id, and a library takes the first, so every reader takes the same one, its `layout` as the store holds it, a number or not, so that one of no layout reaches the verdict to be refused (#479); `foreignNodes` gives a row where the graph holds a node other than the stamp and the schema marker; `restampLayout` sets the stamp's `layout`, binding `restampParameters`, only while it holds none, in one statement; and `layoutObjects` lists the indexes, tables and triggers Drivine may have made for the graph, each `{name, type}`. The last two are null on a graph engine. See `storeLayout`. | | `storeLayout` | The verdict on a graph by its store layout (#161), which `StoreLayout.verdict` gives and each library acts on at its first connection, before any statement runs: before the store's `ensuring`, `ddl` or the stamp's `prepare` makes anything, as this layout's lock table, which they make, is what tells a graph of this layout from an earlier one's where a clear deleted its stamp. A graph whose table of nodes isn't there yet is new, and needs no verdict. Its `firstConnection` cases hold each library to that order, which no statement of the module's can: each library's runner sets a case up on its store (an earlier layout's table of nodes holding a value, with no stamp), opens a manager of the graph, and checks that its first connection refuses it with the message `refuse` (`{graph}` the graph again), not another error, and makes none of `absent`, this layout's lock table. Each case gives the `store`, the `stamps` `readStamps` read (their `layout`, null where a stamp has none), whether `foreignNodes` gave a row, and the `objects` `layoutObjects` listed, each `{name, type}`. Its `verdict` is `"current"`, the graph to be used; `{stamp: {drops}}`, the graph, which holds no node but Drivine's own, re-stamped: each of `drops` run, the earlier layout's indexes, tables and triggers and their catalog records, then `restampLayout` with what `restampParameters` names, then the stamps read back and the objects listed again, and judged again, anything but `"current"` refused, so a store raced by an earlier library is never used on a guess; or `{refuse}`, the message the library refuses the graph with. Which verdict a graph gets is [the layout's verdict](#the-layouts-verdict)'s table. A library from before layouts reads no `layout`, and can't refuse a graph this one wrote: the upgrade notes say not to point one at it. | | `nodeStamps` | The node stamp's property and form, two tokens of `token` hexadecimal digits joined by `separator`. `tokens` are the text of a token of 64 `bits`, as Java's `String.format("%016x")` writes it. Each of `stamps` is a stored stamp, its `nodeToken` (what comes before its first colon, or all of it), its `linksToken` (what comes after, or null for nothing), whether it is `twoTokens` (33 long, with its colon at 16), whether it `hasNodeToken` (longer than 16, with its colon at 16), and the stamp it is `withoutLinks`. `neverStamped` is what a save reports as the stamp of a node it found with none. | @@ -372,10 +375,11 @@ nodeStamps: {property: "__drivine.stamp", token: 16, separator: ":", neverStampe ### The layout's verdict -A SQL store's layout is 2, a graph engine's 1, and a stamp with no `layout`, or one that is no number, is 1: on a graph engine that is its own, on a SQL store an earlier one. The verdict is the first row of this table that the graph meets, and every graph meets one: the module's `StoreLayoutTableTest` asks it of every combination of an engine, the stamps (none, this layout's, an earlier one's, one with no `layout`, one whose `layout` is no number, a later one's, this one's beside a later one's or beside one with no `layout`), whether the graph holds values, the objects the store lists (any set of an earlier layout's generated names, `_ix_…`; this layout's lock table, `_lock2`; its generated names, `_uq2_…`; a later layout's, `_ix3_…`, and its lock table, `_lock3`; a migration's checkpoint, `_migrate2`; another graph's whose name begins with this one's; entries with no name, or one that is no text), and whether the library gives the store's DDL, and holds each to its row. DDL of another store than the graph's is the library's error, thrown. The values are whether the graph holds a node other than Drivine's own; the objects are known as a layout's only by the names it generates, where the library gives the DDL, and a graph engine lists none. +A SQL store's layout is 2, a graph engine's 1, and a stamp with no `layout` is 1, as a library from before layouts stamps: on a graph engine that is its own, on a SQL store an earlier one. A stamp whose `layout` is no whole number from 1, as a number or its text (`"two"`, `2.7`, `0`, `-1`, `4294967298`), is of no layout Drivine writes: it is refused, naming the layout as stored (row 0), never read as another layout and the graph dropped or restamped on the guess (#479); so is a migration that reads one under its lock. The verdict is the first row of this table that the graph meets, and every graph meets one: the module's `StoreLayoutTableTest` asks it of every combination of an engine, the stamps (none, this layout's, as a number and as text, an earlier one's, one with no `layout`, a later one's, this one's beside a later one's or beside one with no `layout`, and those of no layout: a text that is no number, a whole number past an Int's range as a number and as text, a fraction, 0, a negative, and one beside this layout's), whether the graph holds values, the objects the store lists (any set of an earlier layout's generated names, `_ix_…`; this layout's lock table, `_lock2`; its generated names, `_uq2_…`; a later layout's, `_ix3_…`, and its lock table, `_lock3`; a migration's checkpoint, `_migrate2`; another graph's whose name begins with this one's; entries with no name, or one that is no text), and whether the library gives the store's DDL, and holds each to its row. DDL of another store than the graph's is the library's error, thrown. The values are whether the graph holds a node other than Drivine's own; the objects are known as a layout's only by the names it generates, where the library gives the DDL, and a graph engine lists none. | # | Stamps | Values | Objects | Verdict | |---|---|---|---|---| +| 0 | one whose `layout` is no layout | any | any | refused: names the layout as stored, which something other than Drivine wrote | | 1 | of two layouts or more | any | any | refused: stamped by two versions at once | | 2 | of a later layout | any | any | refused: written by a later Drivine, to be upgraded | | 3 | any | any | a later layout's (`_ix3_…`, `_lock3`) | refused, as row 2 | @@ -442,7 +446,7 @@ The module's `LayoutMigrator`, or the JSON request `{"migrate": …}`, runs a mi 5. **Check.** Each uniqueness constraint the catalog recorded as the migration began, kept in its checkpoint, is checked for keys that repeat, by the schema plan's own sample of what a constraint would refuse (`sampleConflictsQuery`), the store's SQL, run uncompiled as the schema plan runs it (a `query` of purpose `collisions`). After the writes it is exact, over layout 2's values, as the index an application's schema plan makes would refuse them: keys that repeat end the run `collisions`, with samples, every value rewritten and the checkpoint kept, so the graph stays refused as part way through a migration. The user corrects the rows with the store's own tools (`psql`, `sqlplus`, `sqlite3`), keeping their values in layout 2, and resumes; the migration offers no statement of its own to run on a graph part way through one. In a dry run the check reads the constraints from the catalog (`uniques`) and runs over layout 1's values, listing possible collisions: it misses values that become equal only once rewritten (two spellings of one moment) and counts a date and the text that spells it as one. 6. **Finish.** Any of the earlier layout's objects still listed are dropped, with their records, as in step 3; every stamp is given this layout (`stampLayout`, or, where the graph has none, the stamp's `assignIfAbsent` with the library's own id and moment: `assignStamp`), and the checkpoint table dropped last (on Oracle with `PURGE`). The graph is then judged again, and must be current, an ordinary graph of this layout (`migrate.yaml`'s `finished`): the run ends `migrated`. **No index or constraint is made**: an application's schema plan makes its declared ones at its next start, as it makes any it finds missing, and until one does, statements give the same answers, unindexed, so slowly on a large graph; a graph migrated with no application has none. **The count store is left empty**, as on any fresh store of this layout, its counts seeded when Drivine begins to keep them (#349). Every report from the check on (a dry run's, `collisions` and `migrated`) says both, as its `notes`; one that ends before it, refused or `invalid`, wrote nothing for them to be of. -The checkpoint, the row `checkpoint` of the checkpoint table, holds the layouts it migrates between, the table and the id the write is after (no table once every row is written), the digest of the declarations, whether it keeps values not of their declared kind, the report so far, the uniqueness constraints the catalog recorded as the migration began (each its label, then its properties), which the check reads, and the fingerprint of the graph as the migration found it: the SHA-256 of Drivine's own nodes and the graph's size, as canonical JSON, none of which a rewrite changes. A resume reads them again, and refuses a graph whose fingerprint differs, one written to under the migration, or declarations, or an option to keep values not of their kind, that differ from those the migration began with. Once every row is written (no table), a resume checks neither: what is left reads the graph as it then is, a row corrected after a collision, or a stamp given this layout before the checkpoint was dropped. While the checkpoint table is there the verdict refuses the graph (row 4), as part way through a migration. Under the lock, a migration that judged the graph beside another that has since finished, and dropped its checkpoint, finds the stamp of this layout and no checkpoint, beginning or resuming, in the table it made again, or made and stopped (the graph refused as part way through until it is begun again): it drops that empty checkpoint table, and ends refused, having written nothing. +The checkpoint, the row `checkpoint` of the checkpoint table, holds the layouts it migrates between, the table and the id the write is after (no table once every row is written), the digest of the declarations, whether it keeps values not of their declared kind, the report so far, the uniqueness constraints the catalog recorded as the migration began (each its label, then its properties), which the check reads, and the fingerprint of the graph as the migration found it: the SHA-256 of Drivine's own nodes and the graph's size, as canonical JSON, none of which a rewrite changes. A resume reads them again, and refuses a graph whose fingerprint differs, one written to under the migration, or declarations, or an option to keep values not of their kind, that differ from those the migration began with. Once every row is written (no table), a resume checks neither: what is left reads the graph as it then is, a row corrected after a collision, or a stamp given this layout before the checkpoint was dropped. While the checkpoint table is there the verdict refuses the graph (row 4), as part way through a migration. Under the lock, a migration that judged the graph beside another that has since finished, and dropped its checkpoint, finds the stamp of this layout and no checkpoint, beginning or resuming, in the table it made again, or made and stopped (the graph refused as part way through until it is begun again): it drops that empty checkpoint table, and ends refused, having written nothing. One that finds there instead a stamp whose `layout` is of no layout, written meanwhile by something other than Drivine, ends refused, having written nothing, and keeps its empty checkpoint table, so the graph stays refused until the stamp is corrected and the migration resumed (#479). An action is one of a `query`, whose rows the planner reads, each one JSON object read into a map; an `execute`, in auto-commit; a `transaction` of `execute`s, all of them or none; `prepare`; `lock`; and `assignStamp`. Each is answered `rows`, `ran` or `failed`, with the store's message, which ends the migration as `failed`. `migrate.yaml`'s `statements` pin each store's statements for the graph `drivine`, and the module's `LayoutMigratorTest` runs a migration against a store kept in memory, stopped after each action of each round and begun again, and requires every row rewritten exactly once and the rows a migration never stopped gives. @@ -478,6 +482,23 @@ table outgrows the cache, each check is a read and a write of the disk. At scale that took the load from 1,870 s to 219 s. Made again at the end, the foreign keys check every relationship, so one with no node at an end fails the import there. The staging tables are temporary, and dropped at the commit. +A library with no Kotlin types asks the module's JSON entry for the statements (drivine-cypher-spec#435): + +```json +{"bulkStatements": {"store": "postgres", "graph": "g", + "nodes": [{"label": "Person", "key": "id"}], + "relationships": [{"from": {"label": "Person", "key": "id"}, "to": {"label": "Repo", "key": "$slug"}}], + "maintenanceMegabytes": 1024}} +``` + +It is answered with the statements `bulk.yaml` pins, by their names. The statements every import runs come once. +`takenKeys` and `makeNodes` come in `nodes`, one entry for each of the request's. `ambiguousKeys`, `findEnds`, +`missingEnds`, `makeEdges` and `relink` come in `relationships`, likewise. The library runs them in `bulk.yaml`'s order and +does the `COPY` itself. `nodes` and `relationships` may be left out, and `maintenanceMegabytes` is 1024 where it is left out. A +store other than Postgres, a key the request doesn't know, or an empty label or property name, which no statement reads, is +answered with an error. `bulk.yaml`'s `json` pins the +request and what is refused. + ## The schema plan A schema manager decides, from what a store says, what to make, drop, recreate and record, and what to report: drivine4j's `SchemaManager`, `IndexManager` and `ConstraintManager`. The compiler's module (`org.drivine.cypher.store.plan`) decides it once for every library, as a planner with no store: `SchemaPlanner(store, markers)`, whose `start(request, now)` and `resume(state, outcomes, now)` each give a round of actions for the library to run, or the plan done and its report. `plans.yaml` pins its decisions: drivine4j's, the reference, captured from its managers over a scripted store, with no store, for the design's cases 1 to 29 (drivine-cypher-spec#135), and the module's own for case 30, the form check, and case 31, the safe recreate of a uniqueness constraint (whose Oracle, Postgres and SQLite listings and errors are captured from each store), and for the public `IndexManager` and `ConstraintManager` calls (`item`). The module's tests check the planner gives them, round by round, on every target. @@ -556,7 +577,7 @@ An action that throws is answered `Failed`, its `causes` as [a cause](#the-store **What drivine4j decides, which the plan keeps.** A version that changed recreates the owner's items, but not one another owner declares; a first version is adopted. An ensure records the version the marker has, and `recreateOnStartup` doesn't apply to it. A runtime item a later manager hasn't been given is kept in the inventory; a recreate marks it stale, and the next ensure of it recreates it. A key recorded and no longer declared is an orphan, reported and left; a marker with no inventory has none. Only a versioned owner keeps its marker single. Under `FAIL_FAST`, a drift, a violation, an index in the way or an index not built fails the owner once every item has been tried, and its marker isn't written; under `WARN`, each is logged and the marker written. A failure drivine4j's manager catches (the marker's, the lowercased copies' fill and record, a TEXT index off Neo4j, a wait that ran out) ends the owner there, its marker unwritten, and the other owners go on; one it doesn't (DDL the store refused for a reason the planner doesn't read, a read of the copies' record) ends the plan, and the library throws the store's error. A remove keeps an item another owner declares or records, its properties in any order. -**An index built online.** An ensure builds an index so that writes to the graph go on while it is built. On Postgres a range, vector or full-text index is made `CREATE INDEX CONCURRENTLY IF NOT EXISTS`, a statement of its own, and a uniqueness constraint's index `CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS`; on Oracle a range index's two indexes are built `ONLINE`, and a uniqueness constraint's, its range index and its unique index, blocking writes, as before: Oracle's online build of its unique index over keys the data repeats is not refused as a blocking one is, and online builds of its range index beside the blocking build of its unique index deadlocked in the library cache (`ORA-04020`). Sessions issuing the same `CREATE INDEX` at once on one Oracle table deadlock in the library cache even so, each held up about nine seconds or refused (`ORA-04020`), so an ensure on Oracle builds in its turn too, as below (drivine4j#777). The index a recreate builds beside the old one is built as before, blocking writes, on both: another session never sees it part built, or left invalid, and so never takes it for the constraint, nor drops it, mid-recreate. Where the store can't build online, the build is run again as one that blocks writes, and so is each after it in the plan, said once at `WARN` (`{engine} can't build an index online here (), so it is built by a statement that blocks writes to the graph's nodes until it is done.`, then what lets it build online). Postgres refuses `CONCURRENTLY` in a transaction (`25001`): `Ensure the schema outside a transaction to build it with writes going on.` Oracle refuses `ONLINE` on an edition without it (`ORA-00439`): `An edition with online index builds (Enterprise Edition) builds it with writes going on.` A library that ensures the schema on a connection a transaction holds takes a savepoint before a Postgres index build, so the transaction outlives the refusal. A Postgres build cut short or failed leaves its index invalid under its name, which `IF NOT EXISTS` would pass over: the listing gives its record the `status` `INVALID`, and the index too among the objects under Drivine's names, as one cut short before its record was written has none. One invalid while a build of it is under way (`pg_stat_progress_create_index`; a build another role runs in the database, whose index Postgres hides, is taken as maybe its) is listed `BUILDING` instead, recorded or not, as its record is written once it is done: an ensure waits for that build, for as long as it waits for an index of its own to build (a uniqueness constraint's for 30 seconds), and reads how it ended, rather than take it as made or drop it, and one still building past that is said so (an index's, as one still being built is) or thrown (a constraint's). An index of another shape under the name is drift at once, being built or not, and isn't waited for; nor is the index a recreate builds first taken as holding the constraint while it is `BUILDING`. An ensure, or a recreate, drops an index left `INVALID` and builds it again; the drop waits until no online build of any index is under way on the node table (`pg_stat_progress_create_index`, as below), and is a block that, where the index is still `INVALID` (no build of it under way: one another session began since is left, and an ensure of a uniqueness constraint waits for it in the listing, as above), holds the index's table (`LOCK TABLE … IN ACCESS EXCLUSIVE MODE`) and drops it (`DROP INDEX`, the one name) only if it is still invalid then, so a valid index another session built meanwhile is left: reads and writes of the graph's nodes wait while an invalid index is dropped, and only then. The block never waits on the table for a build, which would hold up every read and write of it until that build ended, and whose last phase, waiting for the block's snapshot, would deadlock with it. It is said at `INFO` (`Completed Postgres on