Skip to content

Releases

NHyDB 0.28.2

Choose a tag to compare

@nhydb nhydb released this 12 Nov 10:37

Engine 0.28.2, file format 0.28.2. Files start with the signature
NHYDB followed by the version bytes 0, 28, 2 (the historical numbering
NHYDB016 ends). New block types 14 DIRECTORY and 15 SECONDARY_PAGE,
the superblock field dir_root, a prefix checksum in DATA_DENSE (D28D)
and SPARSE_CELLS (SP28) payloads and SECONDARY indexes as key trees
(SI28); all other blocks and payloads are unchanged. Only format 0.28.2 is
read: files of NHyDB 0.28.0 and 0.27.1 (NHYDB016) and of an unreleased
development format are rejected with CorruptionError naming the format
(see Removed).

Highlights

  • Block directory and file format 0.28.2: opening a file with one
    million single-cell blocks takes ~5 ms / ~7 MB instead of ~0.3 s /
    ~230 MB; prefix checksums in the data payloads.
  • SECONDARY indexes as persistent key trees with an index build of
    bounded memory (external sort): first lookup 0.2 ms instead of 200 ms,
    indexes 5.5x smaller on disk.
  • Automatic index maintenance: indexes stay usable after writes and
    renew themselves; build_indexes() is only needed for new indexes.
  • Central RAM limiter per process: large operations wait or spill
    instead of exhausting memory; last resort ResourceLimitError.
  • Large result sets: faster query planning, streaming rows with
    db.sql_iter(), result files (db.sql_to_file()), background queries
    (db.submit_sql()) and bounded ORDER BY with sorted runs on disk.
  • Delete API: delete_cell, delete_area and delete_record, also
    inside db.batch().
  • The newest write wins across dense and sparse storage on every path.
  • Fast queries on overwritten data: COUNT(*), field scans and NOT
    after overwrites, deletes or sparse cells (KQ-10M field scan 17.7–23.6 s →
    1.0–2.2 s).
  • read_numpy(..., masks=True) tells live cells apart from deleted or
    missing ones.
  • cleanup_compaction() removes the staging file of an interrupted
    in-place compaction.

Upgrade notes

  • Files of NHyDB 0.28.0 and 0.27.x do not open (CorruptionError naming
    the format; the file stays unchanged). There is no migration path: rebuild
    such databases from the source data or exports.
  • Python 3.12–3.15 only (requires-python = ">=3.12"); Python 3.9–3.11
    are no longer supported.
  • Delete API: delete(realm_id, u) and delete_point(realm_id, u, v) are
    removed without aliases. Use delete_record (whole record), delete_area
    (by realm coordinates) or delete_cell (former delete_point). Return
    values changed (see Changed).
  • DENSE fields reject None with ValueError; store a null cell with
    put_cell(..., None).
  • put replaces the BASE record as a whole; a tombstoned BASE field is
    no longer reported as present.
  • New default bound [query] max_result_bytes = 4 GiB: calls that return
    the whole result at once raise QueryLimitError beyond it (before: no
    bound). Use sql_iter()/sql_to_file() for larger results or set 0.
  • len(WriteBatch) counts calls instead of distinct cells; a failed
    WriteBatch.flush() ends the batch. Negative administrative IDs raise
    ValueError.

Known limitations

  • delete_area costs time proportional to the live cells in the area (no
    O(1) range delete; about 15 s for 40 million cells).
  • An index on a field missing from the current BASE shape of a realm reads
    only SPARSE cells; dense values of older shapes are not in the index.
  • A batch() holds every collected call in RAM until flush() (about 105 B
    per cell call, about 86 B per record delete): flush in between and use
    db.delete_area() for mass deletes.
  • RAM limiter on Windows: with a limiter budget that cannot be reached, a
    cache relief can keep the cache budget capped for several seconds up to
    about two minutes (measured 4–131 s) until it is judged ineffective
    (intentional policy).
  • A FULLTEXT conjunction on an index with pending changes is about 4× slower
    until its rebuild; every index rebuild leaves the old trees as dead space
    until a compaction.

Added

  • Delete API.
    • delete_area(realm_id, u_from, u_to, v_from, v_to, *, lane=None, commit=False) deletes every live cell of a rectangle of a realm (bounds
      inclusive), independent of layout, BASE/extension and dense/sparse
      storage, and returns the number of live cells deleted. The call is
      atomic: a size limit, I/O error or RAM-limiter cancel leaves nothing of
      it. Memory stays bounded (macOS M1 Max: peak RSS +41 MB for 3.2 million
      deleted cells).
    • WriteBatch.delete_record(layout_id, object_id) and
      WriteBatch.delete_area(...) next to put_cell/delete_cell. The batch
      keeps the call order and is written as one unit. flush() reports
      "deleted" (the sum the single calls would return); blocks and
      bytes are what the batch appended.
  • read_numpy(..., masks=True) adds "_cells": field name → bool array,
    True where the cell lives (a stored None included). Without masks the
    output is unchanged.
  • cleanup_compaction() and the health check compaction_leftover. A
    <db>.compacting staging file left by a killed in-place compaction is
    reported by health() (path, size, removable) and removed by
    cleanup_compaction() (own lock required) or when a writer opens the
    database.
  • Automatic index maintenance. After writes an index answers from its
    built part plus an in-memory overlay of the changed records (VALUE, TOKEN,
    TRIGRAM, FULLTEXT incl. phrases and BM25 ranking); results equal a full
    rebuild. After a commit the writer renews stale indexes by a merge rebuild
    without a data scan (KQ-10M 1.4–2.3 s instead of 4.3–6.7 s; FULLTEXT over
    10 million documents 12.6 s instead of 36 s), deferred during bulk commits
    and while the RAM limiter is not green; an index that was never built is
    built at the next commit. A failed rebuild never touches committed data.
    • New [index] settings: maintenance ("auto", or "manual" = only
      build_indexes()), rebuild_ratio (0.02), rebuild_min_changes
      (1024), bulk_commit_ratio (0.002), crisis_ratio (0.25),
      overlay_max_bytes (256 MiB).
  • Central RAM limiter. One limiter per process compares the process
    footprint (macOS phys_footprint, Linux RSS within the cgroup limit,
    Windows commit) with (100 − reserve_percent) % of the RAM. Large
    operations (queries, conversions, sorts, index builds, write calls,
    deletes, batch flushes, compact_file) check it at chunk boundaries;
    single operations are not affected. Yellow zone: caches are emptied,
    sorts and index builds spill early, new large operations wait; red: all but
    the oldest wait. As a last resort (cancel_over_limit, default on) the
    operation that keeps the process above its limit is cancelled with the new
    ResourceLimitError (reason; a write call is rolled back). The GIL is
    never held while waiting.
    • New: nhydb.resource_status(), nhydb.cancel_job(id), section
      [limiter] (enabled, reserve_percent, warn_percent, tick_ms,
      notify_wait_s, wait_timeout_s, cancel_over_limit, probe_bytes,
      ram_bytes, dry_run).
    • Statistics file limiter.txt ([limiter_log], default on): one JSON
      line per interval (default 30 minutes; interval_min 1 … 527,040),
      archived as ZIP from 60 MB; default location is the directory of the
      first database of the process.
  • Streaming rows: db.sql_iter() yields the rows of a SELECT in chunks
    (same rows and order as sql()); sql_numpy() builds its columns from
    streamed rows (KQ 5 million rows x 11 fields: 21.8 s / 24.3 GB → 8.9 s /
    0.95 GB; sql_iter 11.0 s / 0.35 GB, first row after 87 ms).
  • Result files and background queries: db.sql_to_file() streams a
    SELECT into a CRC-protected result file (.nhyc, layout in the technical
    documentation, section 14.5) and returns a nhydb.ResultFile (iterate,
    to_numpy(), fetchall(), pin()/unpin(), delete());
    db.submit_sql() runs it in a background thread on a read-only snapshot
    (nhydb.ResultJob). nhydb.cleanup_results() removes leftovers of ended
    processes (no expiry by time). KQ 5 million rows x 11 fields: 8.9 s,
    477 MB (82 MB with zlib).
    • [results] settings: temp_dir (default <system temp>/nhydb-results),
      budget_bytes (0 = none), compress, sort_memory_bytes (beyond it a
      streaming ORDER BY sorts in runs on disk).
  • [query] max_result_rows (default 0 = no bound): queries whose
    estimated result rows exceed it are rejected before they run with the new
    QueryLimitError (subclass of QueryError); explain() and
    sql("EXPLAIN …") report hints for large estimates.
  • [query] max_result_bytes (default 4 GiB, 0 = none): sql(),
    QueryEngine.execute()/search(), sql_numpy(), find_u(), the find()
    iterator and ResultFile.fetchall()/to_numpy() raise QueryLimitError
    beyond it. Iterating a ResultFile stays unbounded.
  • Process-wide cache budget [cache] total_bytes (default 4 GiB) for all
    open database objects of a process (defined by the first object opened;
    a different later value is reported as a warning). New pools
    [cache] posting_cache_bytes (256 MiB), sparse_cache_bytes (128 MiB)
    and index_page_cache_bytes (32 MiB); [cache] vindex_max_marks
    (4 000 000 ≈ 192 MB) and vindex_max_indexes (4 096) are now used.
    stats()["cache"] reports the budget and every pool.
  • SECONDARY indexes as persistent sorted key trees (pages of about
    4 KiB, read on demand): with 1 million keys per index the first lookup
    takes 0.2 ms instead of 200 ms, memory after 15 000 mixed queries is 75 MB
    instead of 722 MB, the index is 16.8 instead of 92 MB on disk. FULLTEXT
    document le...
Read more

NHyDB 0.28.0

NHyDB 0.28.0 Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 22 Oct 09:08

NHyDB 0.28.0

Databases created with NHyDB 0.27.1 or earlier do not open in 0.28.0
(see R013 below). Export the data with 0.27.1 and re-import it with 0.28.0.

The complete list of changes, including new functions and performance
improvements, is in CHANGELOG.md.
Identifiers below are stable references for reported problems.

Fixed

ID Problem in 0.27.1 Status
F001 repair_file could cut intact committed blocks that followed a damaged block. Fixed
F002, N2 A damaged newest superblock could lead to committed data being cut on open. Fixed
F003 Realm and u numbers above a fixed bit length could not be read back after reopening. Fixed
F004 Shape, layout or index IDs above 2^63−1 could make a database unopenable. Fixed
F005 create(overwrite=True) could delete a layout plan or key file belonging to another database. Fixed
F006 A failed create(overwrite=True) could destroy the existing database. Fixed
F007 With relative paths and a later change of the working directory, the layout plan could be written to the wrong directory and the database became unopenable. Fixed
F008 create_shape/create_realm with an existing ID replaced the definition and made existing data unreadable. Fixed – see API behavior
F009 Indexed queries returned wrong results for sparse u above 2^32. Fixed
F010 Indexes returned wrong records in realms that mix CLASSIC with other layouts. Fixed
F011 Damaged index blocks were used without a checksum check and could give wrong results. Fixed
F012 There was no write-free way to open a database; diagnostics (CLI verify, stats, health) changed the file. Fixed
F013 Backups made by compact_file/repair_file could not be restored after two schema commits (layout plan not included). Fixed
F014 varuint/varint values above about 16 390 bits were written but the cell could no longer be read. Fixed
F015 Deeply nested query expressions could crash the process. Fixed
F016 Deeply nested SQL expressions could crash the process. Fixed
F017 Deeply nested MATH expressions could crash the process. Fixed
F018 read_numpy with a huge count could abort the process. Fixed
F019 repair_file kept uncommitted blocks as committed data. Fixed
F020 A file truncated at a block boundary was reported as clean. Fixed
F021, G3-03 Damaged block prefixes were not checksum-checked: reads, range, select and read_numpy could silently return None, an older value or miss records. Damaged SPARSE prefixes, a DATA realm that does not match its shape, and damaged DATA u_start values without overlapping segments now raise CorruptionError. Fixed (remaining case: F021 under Known issues)
F022 Manipulated block counts could cause a panic. Fixed
F023 Writing a large integer to a bytes field (bytes(n)) could abort the process. Fixed
F024 A NumPy float16 column caused unbounded recursion. Fixed
F025 Indexed range queries over None, NaN or mixed values raised TypeError. Fixed
F026 Indexed queries did not see extension fields that remain after delete(realm, u). Fixed
F027 NHySQL FROM <layout> returned records of other layouts. Fixed
F028 Behavior after close() was inconsistent: some reads still returned cached data. Fixed
F029 MATH constant folding ignored math_max_intermediate_bits. Fixed
F030 Cells of a MATH layout could become unreachable after reopening with a different bit limit. Fixed
F031 MATH inputs did not convert floats and numeric strings exactly like Python int(). Fixed
F032 Opening via a path that differs in case or Unicode normalization raised a false CorruptionError. Fixed
F033 NumPy columns were silently reinterpreted (2-D arrays, str, bool, NaN, memoryview); read_numpy dtypes depended on the data. Fixed
F034 CLI errors produced tracebacks and no defined exit codes. Fixed
F035 lock=/lock_timeout_ms= replaced the whole lock configuration. Fixed
F036 A failed compact_file left files behind that blocked a retry. Fixed
F037 Files smaller than the superblock area were reported with negative values. Fixed
F038 Damaged record data raised IndexError instead of CorruptionError. Fixed
F039 Some writes changed values silently (non-finite float results, bytes into utf8, unknown dict keys). Fixed – see API behavior
F041 kernel.dec_value with an out-of-range position could panic. Fixed
F042 The MATH lexer differed from Python for some literals and comment lines. Fixed
F043 MATH identifiers that are not NFC-normalized were accepted. Fixed
F044 kernel.intersect_sorted_ints handled duplicate values differently from the reference. Fixed
F045 == NaN matched through an index but not through a scan. Fixed
F046 Query output differed with and without an index in some return modes. Fixed
F047 delete_cell on a missing cell reported success. Fixed – see API behavior
F048, G2-5 I/O errors were not raised as the matching OSError subclass or named the wrong file. Fixed
F049 The context manager could lose the original exception and keep the lock after a failed commit. Fixed
F050 The lock file followed symbolic links (Unix). Fixed
F051 Empty, identical or directory paths and very small db_max_size_bytes were accepted. Fixed
F054 verify() stopped at the first damage; a stale index was reported as an error. Fixed
F055 get_value did not accept column names. Fixed
F056 Several input checks were missing (BM25 k1, @record_n, search(limit=), lone surrogates in stored JSON). Fixed
N3 Backups made within the same second failed with FileExistsError. Fixed
D006 MathError, LayoutError and QueryError did not derive from NHyDBError; damaged column offset tables could panic. Fixed
R001 On macOS, durability fsync did not order the data writes before the superblock write (risk on power loss). Fixed
R002 A failed fsync or superblock write during commit left the handle usable and could report a commit as durable. Fixed
R004 Opening with lock=False could cut another writer's uncommitted tail. Fixed
R005 Windows: replacing the layout plan or a compacted/restored database failed while another process held the file and was not flushed afterwards. Fixed
R007 repair_file wrote both superblocks with generation 1 and without a sync in between. Fixed
R008 close() after a failed commit did not release file handle and lock. Fixed
R009 Values nested very deeply could overflow the stack. Fixed
R010 Decompression of index data had no size limit. Fixed
R011 Sparse record groups above 4 GiB could have their length truncated. Fixed
R012 The key object was not wiped from memory on release and could appear in debug output; a key file readable by others was accepted without warning. Fixed (remaining part: G2-7 under Known issues)
R014 repair_file inspected the file before taking the lock. Fixed
R016 Internal decode caches could grow without limit during long sessions. Fixed
G2-1 With lock=False, closing a handle without changes could hide another writer's acknowledged commit. Fixed
G2-6 A failed create left its lock file behind. Fixed

Known issues

ID Problem Status
G2-7 Internal states of the HMAC/AES-GCM implementations and temporary buffers holding key material are not guaranteed to be overwritten in process memory. The .nhydb data file is not encrypted. Deferred
F021 Remaining case: with overlapping DATA segments, a damaged u_start in a DATA block prefix may only be detected when that block is loaded or by verify(deep=True). Open
G3-05 Open handles assume blocks are never changed in place. If another tool modifies an already checked block, an open handle may not detect it; reopening checks again. Documented limitation
G3-07 A cell written only as None, without a dense record, is counted by COUNT(*) and Q.all(), while get() returns None and range() skips it. Open
R006 Windows: the .layout.key file inherits the permissions of its directory; NHyDB sets no owner-only ACL. Documented limitation
D004 The [cache] keys vindex_max_marks and vindex_max_indexes are accepted but not used. Open
F057 A utf8 field of a dense record stores any value as text via str(): None written with put/put_dense_batch is read back as 'None', not as a null value (put_cell stores a real null). Open
F058 put_record(layout_id, object_id, get_record(...)) raises SchemaError (unknown column _realm); the metadata keys of a get_record result must be removed before writing it back. Open

API behavior

ID Behavior Status
R013 The schema digest is keyed (HMAC-SHA256). Databases created with 0.27.1 or earlier fail to open with CorruptionError naming 0.27.1; there is no migration. Changed (file format)
– delete(realm, u) hides the dense record only; single cells and extension fields written for that u stay visible. delete_record(layout_id, object_id) removes a record completely; delete_cell/delete_point remove single cells. Intended
F039 Unknown keys in dict rows raise SchemaError, bytes for a utf8 field raise TypeError, non-finite float results raise ValueError. Records returned by get() can be written back with put(). Changed
F040 Non-integral numbers as coordinates, re...
Read more

NHyDB 0.27.1

NHyDB 0.27.1 Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 18 Oct 12:51

Added

  • Prebuilt wheels for CPython 3.9–3.14 on Linux (x86_64, aarch64;
    manylinux_2_28), macOS (x86_64, arm64) and Windows (x64), published on
    PyPI: pip install nhydb.

Changed

  • close() releases the file handle and the write lock immediately, not only
    when the object is released. Afterwards every file access raises
    NHyDBError ("database is closed"); previously reads on a closed database
    could still succeed. Repeated calls have no effect.
  • If the commit in close(commit=True) fails, the database stays open (retry,
    or discard with close(commit=False)). close(commit=False) releases handle
    and lock even if writing the buffer fails; uncommitted data never becomes
    visible, also not after reopening.

Fixed

  • Windows: compact_file() failed with "Access is denied (os error 5)" when
    the database had been closed but the object was still referenced.
  • Windows: the Rust corruption test no longer uses Unix-only positional file
    I/O.
  • Windows: the Python test for rolling back a failed append relies on the
    POSIX file size limit and is skipped on Windows; the same property is
    checked on all platforms by a Rust test with injected write errors.

NHyDB v0.27.0 – Initial Public Release

Choose a tag to compare

@nhydb nhydb released this 17 Oct 16:49

NHyDB v0.27.0 — Initial Public Release

This is the first public release of NHyDB, a mathematical database system based on the Dynadron structure of natural numbers.

NHyDB combines exact integer-based address mathematics with a native Rust storage engine and Python interfaces.

Key Features

  • Mathematical addressing: Exact bidirectional conversion between natural-number cell references and structural Dynadron coordinates.
  • Realm architecture: Structured addressing across large mathematical address spaces, using a fixed Realm span of 10¹⁰⁰.
  • Multiple storage geometries: Support for CLASSIC, COLUMN, PACKED, and CUSTOM layouts.
  • Direct cell and record access: Natural-number references can identify individual storage cells and retrieve their associated logical records.
  • MATH_MAP: Mathematical construction of storage addresses through arithmetic expressions and logical-to-physical Realm mapping.
  • Persistent storage: Compact data representation, secondary indexing, and database query operations.
  • Native implementation: Rust-based database components with Python bindings.
  • Documentation: Technical documentation in German and English.

Validation and Benchmarks

The documented release has passed 51 Rust tests and 71 Python tests.

Comparative benchmarks involving 10 million numerical records with 11 fields each demonstrate high write throughput, compact index structures, and efficient retrieval of large index-based result sets.

The benchmark results represent the measured performance of the current implementations under the documented test conditions.

Scientific Background

The mathematical foundations and database architecture are described in:

Das Dynadron als mathematisches Datenbankprinzip

https://doi.org/10.5281/zenodo.23438748

License

NHyDB is source-available software. Usage is governed by the included LICENSE.md, which restricts use to non-production purposes.

Release Status

Initial public release — Version 0.27.0 (Alpha).