Skip to content

feat(index)!: integers too large for 64 bits keep their declared XSD subtype - #2477

Merged
bplatz merged 14 commits into
nextfrom
fix/numbig-declared-datatype
Nov 21, 2026
Merged

bplatz merged 14 commits into
nextfrom
fix/numbig-declared-datatype

Conversation

@bplatz

@bplatz bplatz commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

An integer too large for 64 bits now keeps the XSD subtype it was written with. "18446744073709551615"^^xsd:unsignedLong reads back as xsd:unsignedLong, before and after indexing, and the same value written as xsd:integer is another term. Until now the index typed these values by value, so every one read back as xsd:integer and two subtypes of one value were one fact. This is part of the v5 index format change.

The same PR stores the NumBig arena in byte-bounded chunks, fixes BIND dropping an integer's subtype, and keeps deletions written before the upgrade in effect.

What changes

  • Format.
    • The arena's values take one of seven new o_types, one per integer datatype plus xsd:decimal (0x800E–0x8014). A v4 root's NUM_BIG_OVERFLOW (0x800B) is still read, by value.
    • A v5 root lists each arena as chunks, each with its entry count. A chunk closes at 16 MiB (IndexerConfig::numbig_chunk_bytes); an entry larger than that is a chunk of its own.
    • Incremental builds keep the closed chunks and rewrite only the last, so adding a value no longer re-uploads the whole arena.
    • GC, pack export and archive/restore cover every chunk.
  • Reads.
  • Writes.
    • Staging names a big integer by its term, so writing one value under two subtypes keeps both.
    • A DELETE DATA naming another subtype than the stored one deletes nothing.
    • This removes fix(transact): retractions name stored facts; RDF text is parsed once #2008's index-independent by-value identity for big integers. Identity now comes from the persisted index key, which still merges subtypes over a v4 index.
  • BIND(?o AS ?v) binds ?o's term, subtype kept (BIND drops a big integer's declared XSD subtype #2058). Like any computed binding it carries no fact t or op, whether ?o was decoded or still encoded.
  • Deletions written before the upgrade. v4 named a deleted big integer as its index read it back, xsd:integer, whatever subtype was stored. Replayed as written, that deletion would name a term the ledger never held, and the deleted value would come back.
    • A new commit header flag (bit 2, FLAG_NUM_BIG_DECLARED) records that a commit was staged against an index that keeps subtypes. It is clear on every v4 commit and on any commit written over a v4 index; the version byte is unchanged.
    • A commit without the flag deletes such a value by value: its retraction also retracts every other term of the value held at its subject, predicate and list place just before the commit. Terms the commit itself names are left to it, so on one t the assertion still holds.
    • This applies in:
      • the rebuild, through a table of live big-integer terms kept in commit order;
      • push validation and staging;
      • reopening a ledger and time travel, worked out once the index attaches;
      • installing a new index on a running instance;
      • another instance catching up, which reloads;
      • rebase, merge and revert, which read the commit's effect from its own branch's history just before it.
    • An incremental build over such a commit builds in full instead. A merge or revert over a branch whose index is still a v4 one is refused (409) until the branch is reindexed.
    • Commit bytes, CIDs and signatures are unchanged. The rebuild's extra retractions are index records, not commit ops, so db:retracts is the same before and after a rebuild.
  • Incremental builds now resolve o_types against the window's datatypes, as a full rebuild does. They used to use the base root's list only, so a datatype first written after the base index (xsd:int, for one) became a custom type and failed to decode.

Upgrading

A v4 index is served as v4 did until the ledger's next build, a full rebuild from commits, which restores every subtype. Until then, a write over the v4 index deletes all of a value's subtypes, as v4 did. Indexes built by earlier next alphas must be rebuilt. See docs/reference/compatibility.md.

Tests

  • it_numbig_declared_datatype runs the same probes before indexing, over a full build, reloaded, after an incremental build and after a rebuild. It covers:
    • two subtypes of one value;
    • typed and bare matches;
    • joins across predicates and graphs;
    • re-upserts and BIND deletes;
    • triple terms;
    • chunk reuse, GC and restore.
  • Against a fixture written and indexed by the 4.2.8 CLI (tests/fixtures/numbig-subtypes-4.2.8, recipe in its README):
    • the v4 answers before the first v5 build;
    • a replacement and a delete that stay in effect through the rebuild;
    • a v4 commit pushed into a v5 ledger, checked live, reloaded, on a peer catching up, at a past t and through the next build;
    • a v5 index installed under a v4 delete still in novelty;
    • reverts and a merge of v4 deletes, including the refusals.
  • it_same_t_one_rule stages its legacy pairs as commits staged by value. It now also reverts and merges a pair. Its delete test now expects a delete under another subtype to delete nothing.
  • I proved every new test fails with its fix reverted.

Fixes #2027
Fixes #1321
Fixes #2058
Partially addresses #2417: item 4, the chunked NumBig arena, which also ends the whole-arena re-upload on each incremental build. Items 1 to 3 (a configurable restore cap, refusing an oversized object at export, and the inline decimals on main) remain.

…subtype

An integer beyond the 64-bit range now keeps the XSD subtype it was
written with, in novelty and in the index alike: two subtypes of one
value are two terms. The index typed these values by value, so every one
read back as xsd:integer and two subtypes of one value were one fact.

- The NumBig arena's values take one of seven typed o_types
  (0x800E-0x8014); a v4 root's NUM_BIG_OVERFLOW is still read, by value.
- Index statistics count them under their datatype.
- BIND forwards an integer's term, with no fact t or op.
- The arena is stored in byte-bounded chunks; incremental builds keep the
  closed ones.
- Staging names a big integer by its term; identity comes from the
  persisted key, which still merges subtypes over a v4 index.
- Incremental builds resolve o_types against the window's datatypes, so
  a datatype first written after the base index keeps its type.

Commits record, in header bit 2, whether they were staged against an
index that keeps subtypes. One without it (every v4 commit, and any
written over a v4 index) deletes a big integer by value: its retraction
also retracts every other term of the value held at its slot just before
it. The rebuild, push, reload, time travel, index install, catch-up,
rebase, merge and revert all read it so; an incremental build over one
builds in full, and a merge or revert over a branch whose index is still
a v4 one is refused until it is reindexed.
@bplatz bplatz added breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section area:storage Storage backends, nameservice, ledger lifecycle, index storage, caches labels Nov 20, 2026
@bplatz
bplatz requested a review from a team November 20, 2026 20:30

@aaj3f aaj3f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bplatz this is careful work, and I'm on board with the design: it makes big integers behave the way small ones already do.

My reading is that this moves integers beyond 64 bits from #2008's one-fact-per-value rule to term identity, so a DELETE DATA naming another subtype deletes nothing and a v4 ledger holding one value under two subtypes shows two after its first v5 build. I added that rule for an index that couldn't keep the subtype, so I think this is right (it's how small integers already behave), and I'm glad to have the change on the record here; I'd just like your confirmation it's the intended decision, and an upgrade-notes line that deletes naming the xsd:integer v4 read back now delete nothing.

Two musts, both in the upgrade path: a delete written while v5 still serves a v4 index can change its answer at the first v5 build, and the rebuild's big-integer table adds over half to peak memory even when no commit needs it. Repros below.

Full review below:


✅ Approving to unblock: please get the upgrade-window delete and the rebuild table's memory in before merging. The format change is the right one and it brings big integers in line with how small integers already behave; the two musts are both in the upgrade path, which is where this PR's care should pay off.

Before merging:

  1. fluree-db-transact/src/commit.rs:792: over a v4 index, retract a deleted big value's other subtypes at staging, so the window matches the first v5 build.
  2. fluree-db-indexer/src/build/rebuild.rs:351: build the big-integer table only when a commit is staged by value, and key it on ids, not owned strings.

Decisions on the record:

My reading is that the BIND fix also changes small integers: BIND(?o AS ?v) of an xsd:int or xsd:short now keeps that subtype rather than becoming xsd:integer, in SPARQL and JSON-LD alike. I think that's right, but I'd like your confirmation it's intended, and a line in compatibility.md outside the big-integer section.

My reading is that a merge or revert over a branch still on a v4 index, when the range holds a pre-upgrade delete of a big integer, now fails with 409 until that branch is reindexed. I think refusing beats guessing, but I'd like your confirmation it's intended, and the upgrade notes should say to reindex branches too.

Notes:

  • The by-value rule is a per-consumer obligation (rebuild, novelty load, historical views, push, catch-up, rebase, merge, revert and the previews all wire it), and one consumer already folds raw commit flakes without it: merge preview into an unborn target (merge_preview.rs:586-592, compute_delta_keys_and_changes) would net a v4 by-value delete as +V^^unsignedLong and −V^^integer now that delta::FactKey keys the datatype (Claude found this by reading; it wasn't run). A commit wrapper whose flakes can only be read after resolving against a ledger view would make the next consumer a compile error; not for this PR, the point wiring is right here.
  • git merge-tree against my #2466, #2463 and #2455 (all on main) adds no conflicts beyond what next and main already conflict on, and the overlapping hunks are identical with and without this PR; against #2436, #2445, #2454 and #2478 on next it merges clean. No ordering constraint from my side.
Adherence: Patterns ✔ · Performance ✖ · Deployment targets ✔ · Testing ✔ · Conventions ⚠️ · verification
  • Patterns/abstractions: ✔ extends the o_type registry, NumBigArena, CurrentFacts and the commit header rather than adding parallel paths; one note above on making the by-value rule structural.
  • Performance (speed first, memory second): ✖ read paths neutral to better (typed o_types answer datatype constraints without decoding; arena lookups unchanged; staging simpler), but the full rebuild regresses on ledgers of big integers (must 2).
  • Deployment targets: ✔ the changed read paths run on every host (embedded, server, wasm32); by-value resolution is per-process and deterministic. The wasm32 job's two clippy steps passed and only its Node runtime smoke failed, on the yanked risc0-zkvm (#2478), so it should re-run after #2478; wasm-smoke ran its wasm32 tests green on this SHA.
  • Testing: ✔ 13 new integration tests in grp_index, all green in CI on this SHA; Claude's mutations of the rebuild and novelty paths each turned the v4-fixture tests red. Missing: the upgrade-window case (must 1) and SPARQL twins of the JSON-LD typed probes.
  • Conventions: ⚠️ thorough multi-line commit body and docs; the two docs sentences on the upgrade window over-claim (optional above), and the small-integer BIND change wants a compatibility line.

Verified at 6fd71d38a: CI test (17,993 tests) green; on a box Claude reproduced term identity for small and big integers on v4.2.8, next and this PR, the upgrade from a v4.2.8 store (growth at the first build, a v4 delete kept, the window divergence), typed constants in SPARQL vs JSON-LD, alpha.3 roots, mutation checks of the PR's tests, and the rebuild's memory and time against next.

Approving so you can merge once those two are in, but maybe worth considering the docs notes and the SPARQL constant fix while you're there.

Comment thread fluree-db-indexer/src/build/rebuild.rs Outdated
shared.schema_hook = Some(crate::stats::SchemaExtractor::new());
// Every commit is read in order, so the retractions of big
// integers staged by value can be told what they retract.
shared.big_integers = Some(Default::default());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (CRITICAL, memory and rebuild time): the full rebuild keeps every live big integer in an owned-string table for the whole replay, whether or not any commit was staged by value.

shared.big_integers is set on every full rebuild, and BigIntegerTerms::note (big_integers.rs:77-115) records each op on an integer beyond i64 under a Slot of four owned Strings (graph, subject, predicate, value) plus a Vec of owned datatype names, kept in stored until the replay ends. Nothing reads it unless a commit was staged by value, which a v5-native ledger never has, and the indexer's memory budget doesn't cover it. The module doc says "only big integers are kept, so the table stays small", but it grows with every live big-integer fact in the ledger.

Claude measured it on a c7i.4xlarge (fluree reindex of a ledger of 2M subjects, each holding one xsd:unsignedLong above i64::MAX, two interleaved rounds): in a release build, peak RSS went from 2,044,188 / 2,076,592 KB on next to 3,203,736 / 3,211,308 KB here (+56%), and wall time from 5.50 / 5.30 s to 7.99 / 7.80 s (+46%). With this line removed, head came back to 1,950,228 / 2,116,224 KB, so the table is the whole memory delta, about 600 bytes per live big integer, and about three-quarters of the time delta (6.28 / 5.98 s; the remaining ~0.7 s Claude didn't isolate). The same 2M values below i64::MAX were flat. And the first v5 build of every upgraded ledger is a full rebuild, so a ledger that keys records by 64-bit unsigned ids or hashes (half of which exceed i64::MAX) pays this during the upgrade itself, with no bound.

Suggested fix: build the table only when the chain holds a commit staged by value (header bit 2 is in the first bytes Phase A's envelope probe already reads, load_commit_envelope_by_id reads from byte 0), and key it on the resolver's ids (graph id, subject id, predicate id, list place, arena handle) and a datatype id rather than owned strings, so the upgrade rebuild that does need it holds a few dozen bytes per entry instead of hundreds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 656afac. The table is built only when the lineage holds a commit staged by value (read from each envelope's header in Phase A) and dropped after the last one. It's keyed on a 16-byte SHA-256 digest of the slot rather than resolver ids, since a rebuild's subject ids are chunk-local until Phase C.

check_index_loaded(&base.snapshot)?;
// The typing of the index the retractions were read from, which says
// what a retraction of a big integer names.
let num_big_typing = crate::current_facts::num_big_typing(&base);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: a delete written in the upgrade window can show one answer and then change it at the first v5 build.

Over a v4 index, FactIdentity keys a big integer by its persisted index key (current_facts.rs:589-593), which exists only when the v4 arena already holds the value, so a value first written after the upgrade is named by its term. The commit is still stamped by value here (num_big_typing(&base) is ByValue over a v4 index), so every later reader (index install, the rebuild, a reload, time travel) also retracts the value's other subtypes held at that slot.

Claude reproduced it from a store the v4.2.8 CLI wrote and indexed, with this PR's CLI: it inserts ex:y ex:n "18446744073709551613" as both xsd:unsignedLong and xsd:integer, then DELETE DATA of the xsd:unsignedLong term commits 1 flake, and the query shows "18446744073709551613"^^xsd:integer still there. After head's first fluree index, ex:y has no value, and a query at t:3 agrees. v4.2.8 itself deletes both at write time (2 flakes). So a value the user saw survive a delete disappears when the index catches up, which is the #2027 shape this PR otherwise fixes.

Suggested fix: when the base's typing is by value, add the other subtypes' retractions at staging, with the PR's own by_value_retractions(&base, &flakes, t), so policy, the staged view and the commit all carry them; the later by-value resolution then finds them already named. That makes the window answer what the build answers, and makes "deletes all of them, as an earlier release did" true for a delete that names a stored term. The fixture covers this cheaply: two subtypes of a new value over v4/numbig, delete one, assert both gone before and after the first v5 build.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in bec2d39

Comment thread docs/reference/compatibility.md Outdated

**Upgrading.** An index an earlier release built is served as it was, by value, until the ledger's next index build. That build is a full rebuild from the commits, which hold each value's datatype, so it restores every subtype: a ledger that held one value under two subtypes then holds two terms. A ledger with no new commits keeps its earlier index until one is built (`fluree reindex`).

Until that build, a write is read against the earlier index, which holds one such value's subtypes as one fact read back as `xsd:integer`, so deleting the value under any of its subtypes deletes all of them, as an earlier release did.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is more of a precision note. "Until that build, … deleting the value under any of its subtypes deletes all of them, as an earlier release did" holds only for a value the v4 index already holds. For a value first written after the upgrade, a DELETE DATA naming another subtype commits nothing: Claude ran the same writes on a store the v4.2.8 CLI indexed, and v4.2.8 deletes "18446744073709551614"^^xsd:unsignedLong under xsd:integer (1 flake) while head over the same v4 index commits 0 flakes and the value survives its first build. docs/transactions/retractions.md:333-335 says the same.

We may want to narrow both to "a value the earlier index holds", or, if you'd rather the window match v4 fully, name such values by value while the typing is by value. It's minor, but if you agree it's right I'd rather see it folded in now than lost in the backlog.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e9f4ef2 (narrowed both docs rather than matching v4 for values written since the upgrade).

DELETE { ex:k ex:n ?v } WHERE { ex:k ex:n ?o BIND(?o AS ?v) }"#;

/// A probe matching a value under one datatype. A typed constant in a triple
/// pattern or an expression loses an integer subtype at lowering (on v4.2.8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code didn't introduce this, but this PR makes it more visible: a SPARQL typed constant for an integer subtype other than xsd:integer, xsd:int or xsd:long matches nothing in a triple pattern. lower_typed_literal (fluree-db-sparql/src/lower/term.rs:313-324) coerces only those three, and every other integer subtype falls to _ => FlakeValue::String (:441-444). So the comment here isn't quite right: the constant doesn't lose its subtype, it matches nothing.

Claude checked on next and on this PR: { ?s ex:n "5"^^xsd:unsignedLong }, "5"^^xsd:short and "5"^^xsd:nonNegativeInteger all return no rows over stored terms of exactly those types, novelty and indexed, and so does { ?s ex:n "18446744073709551615"^^xsd:unsignedLong } over three stored xsd:unsignedLong terms; the JSON-LD value object {"@value": "18446744073709551615", "@type": "xsd:unsignedLong"} finds all three on head. With this PR the subtype is part of a big integer's identity, so SPARQL can't name the term the PR now preserves except through FILTER(DATATYPE(…)), as the probes here do.

#1686 fixed the datatype side of this lowering; routing every XSD datatype through fluree_db_core::coerce::coerce_string_value, as it already does for double, float, WKT and JSON, would close the value half, and the SPARQL twins of the JSON-LD value-object probes in check would pin it. Commenting here because fluree-db-sparql/src/lower/term.rs is not in this diff. It's minor, but if you agree it's right I'd rather see it folded in now than lost in the backlog.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in a080026 (lowering, SPARQL twins in check, test comment) and 07a4bd2 (compatibility note). Out-of-range constants are now refused, xsd:int included.

// every computed binding it carries no fact's `t` or op,
// however the source is held.
Some(Binding::Lit {
val: val @ (FlakeValue::Long(_) | FlakeValue::BigInt(_)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forwards every integer's term, small ones too, which I think is right. It does mean BIND(?o AS ?v) of an xsd:int, xsd:short or xsd:unsignedLong now binds that subtype rather than xsd:integer on every ledger: Claude saw next bind xsd:integer and this PR keep the subtype, in SPARQL and in JSON-LD's ["bind", "?v", "?o"]. compatibility.md mentions BIND only in the big-integer section, so we may want a line saying that DATATYPE(?v), GROUP BY ?v and DISTINCT over a bound integer now see the declared subtype. Minor, and worth folding in with the other docs edits.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in cc6396c

let cid = read_cid(data, pos)?;
numbig.push((p_id, cid));
let chunks = if wide {
let chunk_count = read_u32_at(data, pos)? as usize;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of a question than a suggestion. The root keeps version byte 4 with a new NumBig layout, so a ledger indexed by the v5.0.0-alpha.3 release with a NumBig arena now fails at open with FIR6 decode: root: truncated at cid bytes (need 48928 at offset 1547, have 5546), which blocks writes and fluree index until fluree reindex (Claude checked with the released alpha.3 CLI). next already can't serve an alpha.3 index (V3 cursor: Unknown frame descriptor at query time), so this isn't a new incompatibility, only a less clear failure than f8950668e's refuse-by-version. Is a version bump (or a sentence in the upgrade notes saying alpha indexes must be rebuilt) worth it while alphas are out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No version bump: v5 keeps compatibility with v4 indexes only, not between v5 alphas, so an index an alpha built needs fluree reindex.

let phase = Instant::now();
let bytes = cs.get(cid).await.map_err(storage_io_error)?;
let mut chunks = Vec::with_capacity(nb.chunks.len());
for chunk in &nb.chunks {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but the chunks are fetched one at a time here, and again in incremental_resolve.rs:334-347. On remote storage an arena of N chunks becomes N sequential round trips at open; a buffered(k) fetch would hide them. I don't think it matters at today's sizes, so take it or leave it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ced2677

/// never changes it, and re-splitting from the start of an arena's last chunk
/// gives the chunks a split of the whole arena would end with. An incremental
/// build keeps every other chunk.
pub fn write_numbig_arena_chunks(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The greedy split with closed chunks that never change is a really nice property to build on: an incremental build rewrites only the last chunk, a full rebuild cuts the same chunks, and appending_keeps_every_chunk_but_the_last pins exactly that. Please keep it.

…atatype

# Conflicts:
#	docs/design/index-format.md
…every subtype

Over an earlier release's index a commit is staged by value: its
retraction of an integer too large for 64 bits stands for every subtype
of the value at that slot, and every later reader (the first v5 build,
a reload, time travel) reads it that way. That index holds a value's
subtypes as one fact, but a value first written after the upgrade is not
in its arena, so novelty keeps it under each subtype and staging named
only the term the delete gave. The window showed the other subtype
surviving, and the first v5 build then removed it.

Staging over such an index now adds the retractions of the value's other
stored subtypes, as the earlier release staged them, so policy, the
staged view and the commit all carry them and the first v5 build finds
them already named.
…mit needs it

A full rebuild kept the terms of every live integer too large for 64 bits
in a side table for the whole replay, as four owned strings and a list of
owned datatype names per slot, though only a commit staged by value ever
reads it. On a ledger of 2M such values that added over half to the
rebuild's peak memory and time, including on a ledger this release
created, which holds no such commit.

The first-parent walk now reads each commit's big-integer typing from the
header it already fetches and reports the newest commit staged by value.
The rebuild builds the table only when there is one and drops it once
that commit is resolved, so a ledger with none keeps nothing. Where it is
kept, as in the first v5 build of an upgraded ledger, a slot is the first
16 bytes of the SHA-256 of its graph, subject, predicate, list place and
value, with its datatypes as ids into a small list: about 40 bytes per
live big integer instead of hundreds.

CommitEnvelope gains num_big_typing, and
collect_first_parent_cids_with_split_mode returns a FirstParentWalk.
…e deletes by value

With no commit on the target, a merge adopts the source's whole history,
and every reader of a commit staged by value reads its retraction of a
big integer as one of every subtype the line held. The preview's change
set folded those commits' raw flakes instead, so the v4 replacement of
a big xsd:unsignedLong showed the xsd:unsignedLong still held and an
xsd:integer, never held, retracted.

That branch now reads the source's commits, resolves the by-value ones
on the source's line as the diverged branch already does (commit_data's
Line), and folds the result. The fold that walked a store and netted raw
commit flakes, compute_delta_keys_and_changes, had no other caller and
is replaced by delta_keys_and_changes_of over commits already read.
…mber

SPARQL lowering coerced only xsd:integer, xsd:int and xsd:long constants
to numbers. Every other integer subtype fell through to a string, so
"5"^^xsd:short or "18446744073709551615"^^xsd:unsignedLong in a triple
pattern matched nothing, even over stored terms of exactly that type,
while the JSON-LD value object for the same term found them. Now that a
big integer keeps its subtype, SPARQL could name such a term only
through FILTER(DATATYPE(...)).

Every XSD integer subtype now goes through the write surfaces' parser,
coerce_string_value, as double, float, WKT and JSON already do: the
constant is the number, under its declared datatype, and a lexical form
outside the subtype's range ("70000"^^xsd:short, "-1"^^xsd:unsignedLong)
is refused as a write refuses it. That also range-checks xsd:int, which
used to accept any 64-bit value. The same constant in an expression is
now the number too rather than a string.

The NumBig probes check each typed SPARQL triple-pattern constant
against its JSON-LD value-object twin at every index stage.
Opening an index, and seeding an incremental build, read each arena's
chunks one after another, so on remote storage an arena of N chunks cost
N sequential round trips. Both sites now issue up to
NUMBIG_CHUNK_FETCH_WIDTH (8) reads at once and keep the chunks in order.
An arena of one chunk, the common case, reads as before.
The upgrade notes said that until a ledger's first v5 build, deleting a
big integer under any of its subtypes deletes all of them. That holds
for a value the earlier index holds. A value first written since is held
under each subtype it was written with: deleting it under one of those
deletes all of them, and deleting it under a subtype it isn't held under
deletes nothing. Both the compatibility notes and the retraction guide
now say so.
The compatibility notes now say that a typed constant of an XSD integer
subtype in SPARQL matches stored terms of that subtype, where it used to
match nothing, and that one outside its subtype's range is refused,
xsd:int included.
…d branches

The compatibility notes now say, outside the big-integer section, that
BIND(?o AS ?v) keeps an integer's XSD subtype for every integer, small
ones included, so DATATYPE, GROUP BY and DISTINCT over the bound
variable see it.

The upgrade notes add two points: after a ledger's first v5 build a
delete naming the xsd:integer an earlier release read back deletes
nothing where the value was written under another subtype, and each
branch keeps its earlier index until its own next build, so branches
need reindexing too.
@bplatz

bplatz commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

From the review summary:

  • Retract a deleted big value's other subtypes at staging over a v4 index: Addressed in bec2d39
  • Build the rebuild's big-integer table only when a commit is staged by value, and key it compactly: Addressed in 656afac
  • Big integers move to term identity: intended. Upgrade note that a delete naming the xsd:integer v4 read back now deletes nothing: Addressed in cc6396c
  • BIND keeps a small integer's subtype: intended. Compatibility line outside the big-integer section: Addressed in cc6396c
  • Merge or revert over a branch still on a v4 index is refused (409) until reindexed: intended. Upgrade notes say to reindex branches: Addressed in cc6396c
  • Merge preview into a target with no commits folds raw commit flakes: Addressed in b2c6a99 (reproduced first: it netted the v4 replacement as +V^^unsignedLong and −V^^integer)
  • wasm32 after chore(wasm-probe): lock the engine's dependencies, risc0-zkvm 3.0.6 included #2478: next merged in 8bcc777

…ty holds

A commit staged by value deletes a big integer under every subtype held
at its slot just before it. Push applied that only when the receiver
already had an index that keeps subtypes, and so did novelty when a
ledger reloaded, on the reasoning that an earlier release's index holds
a value's subtypes as one fact. That index does, but novelty over it
holds a value written after the index was built under each subtype it
was written with. A v4 client's delete, which names the value as
xsd:integer, then left the other subtype behind until the first v5 build
removed it; and with only another subtype held, push refused the delete
(422) as retracting nothing.

Push now works out a by-value commit's retractions whatever the
receiver's index, and so does novelty on load, so the receiver answers
the same before and after its first v5 build.
… reload and rebuild

A commit staged by value that deletes a big integer held in a reifier's
object slot retracts the slot under every subtype held there. Push stages
those retractions with the commit, so its rdf:reifies link was retracted
live. On reload, novelty adds them after the index's links are derived,
and a full rebuild added them as records the link synthesis never saw,
so the reopened ledger and the rebuilt index both kept the stale link.

Novelty now derives, for the reifiers whose slots the added retractions
touch, the links it does not hold yet (or leaves them to the link base
when links are still waiting for an index, which replays every op novelty
then holds), and returns them for dictionary registration. The rebuild
passes each added retraction through link synthesis as it does the
commit's own ops.
A full rebuild resolves each retraction a by-value commit makes of a big
integer against every subtype stored at its slot, and checked each
candidate against all of the commit's ops and all retractions added so
far. A commit deleting n such values cost O(n^2): in a debug build,
10k / 20k / 40k deletions took 2.0 / 8.2 / 32.7 s in end_commit. A set of
the (slot, datatype) terms named or added makes the check constant time:
18 / 38 / 76 ms.

by_value_retractions, which staging over a v4 index, push and novelty
reload use, had the same shape, checking each candidate against every
retraction added and every flake of the commit; it now keeps a set of
the commit's big-integer terms and returns early when no retraction
holds anything.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:storage Storage backends, nameservice, ledger lifecycle, index storage, caches breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants