Skip to content

sqlitedb: announce and time the one-time search index build - #231

Merged
stevevanhooser merged 2 commits into
mainfrom
claude/did-base-id-index
Oct 24, 2026
Merged

stevevanhooser merged 2 commits into
mainfrom
claude/did-base-id-index

Conversation

@stevevanhooser

Copy link
Copy Markdown
Contributor

Follow-up to #229.

Problem

Opening a database that predates the search indexes doc_data_doc_idx and doc_data_field_value builds them, and it does so silently. doc_data_field_value holds a copy of every field value.

For a large dataset the build can take minutes, especially on a slow or synced drive: 100,000 documents can mean tens of millions of doc_data rows. During that time the open just appears to hang. This was reported on a real 100,000-document dataset that sat for more than 2 minutes on open.

While the build sorts, the .sqlite file doesn't grow, which makes it harder to recognise. SQLite sorts in memory or in etilqs_* temp files, and only writes the finished index into the database at the end.

Change

ensure_search_indexes now prints three kinds of message:

  • Before each index it builds: its name, the database, roughly how many rows it covers, and that this happens once and can take minutes. The row count comes from max(rowid), which costs nothing; count(*) would scan the table.
  • After each build: how long it took.
  • If a build fails (for example on a read-only file): that searches will run without that index.

A database that already has the indexes opens without printing anything.

Example:

DID: adding search index doc_data_field_value to /data/ds/.ndi/did-sqlite.sqlite (about 23,456,789 rows). This happens once per database and can take several minutes for a large one...
DID: added search index doc_data_field_value in 142.3 s.

groupDigits is a new private static helper that formats the row count.

Tests

TestSearchIndexes/testIndexesAddedWhenOlderDatabaseOpened checks two things:

  • Opening an older database announces and times each index (captured with evalc).
  • The next open of the same database prints nothing about indexes.

Not run here: there's no MATLAB in this environment.

DID-python

The same change is in VH-Lab/DID-python's claude/did-base-id-index branch; its PR follows. Its bridge entry points at 5b7220b, the last commit here, so please merge with a merge commit, as for #229.


Generated by Claude Code

Opening a database that predates doc_data_doc_idx / doc_data_field_value
builds them, silently. doc_data_field_value holds a copy of every field
value, so for a large dataset (100,000 documents can be tens of millions
of doc_data rows) on a slow or synced drive the build takes minutes and
the open just appears to hang - reported on a real 100,000-document
dataset that sat for over 2 minutes.

ensure_search_indexes now prints, before each index it builds, its name,
the database, the approximate number of rows (max(rowid), which costs
nothing) and that this happens once and can take minutes; afterwards, the
time it took; and, if it cannot be built (read-only file), that searches
will run without it. A database that already has the indexes opens
without printing anything.

Test: TestSearchIndexes checks the announcement and timing for each index
when an older database is opened, and silence on the next open. Not run
here: no MATLAB in this environment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dv7SxVR8MCu3MKpUvwwUia
It only formats the row count in ensure_search_indexes' message; as a
public static method it would also need a DID-python bridge entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dv7SxVR8MCu3MKpUvwwUia
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

450 tests  ±0   450 ✅ ±0   2m 10s ⏱️ +5s
 39 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 5b7220b. ± Comparison against base commit 8ae33fd.

@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.86207% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.29%. Comparing base (8ae33fd) to head (5b7220b).

Files with missing lines Patch % Lines
src/did/+did/+implementations/sqlitedb.m 75.86% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #231      +/-   ##
==========================================
+ Coverage   66.28%   66.29%   +0.01%     
==========================================
  Files          66       66              
  Lines        4674     4694      +20     
==========================================
+ Hits         3098     3112      +14     
- Misses       1576     1582       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stevevanhooser
stevevanhooser merged commit e4a4287 into main Oct 24, 2026
6 checks passed
@stevevanhooser
stevevanhooser deleted the claude/did-base-id-index branch October 24, 2026 17:46
jesshaley pushed a commit that referenced this pull request Oct 29, 2026
…ad of adding a second

testADeclaredCoordinateSystemEdgeIsReadFromTheSchema inserted a required
coordinate_system_id into a copy of statement.json. Against did-schema #231,
which declares the edge (optional, [site frame is a coordinate system]), the
copy then held two declarations. did2.build took the later, optional one and
raised no did2:build:missingEdge; the validator, which unions required edges,
raised did2:validation:emptyRequiredDependency (Quick migrator tests run
40892458228 on that schema). When the schema already declares the edge, the
test now sets that declaration's mustBeNonEmpty to true; otherwise it inserts
as before. The assertions are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxKLA8Tbf9cpvDe7fuVeKf
jesshaley pushed a commit that referenced this pull request Oct 29, 2026
…egans's does

did-schema #231 recorded openminds:species/caenorhabditisElegans as
NCBITaxon:6239's equivalent ([species text is the openMINDS equivalent],
Jess Haley, 2026-10-29). The fixture of
testAnOpenmindsIdThatDoesNotRebuildIsCarried used exactly that id, so it now
rebuilds and the document converts (Quick migrator tests run 40917656427:
0 passthroughs, 1 expected). The fixture keeps the NCBITaxon:6239 term and
names an id with no recorded equivalent, which is the case the test is about.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxKLA8Tbf9cpvDe7fuVeKf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants