Repository navigation
Commit 3acc58e
committed
sqlitedb: make id, isa and regexp searches fast (port of DID-matlab#229)
NDI's most common searches -- base.id or isa daqsystem, ANDed with
base.session_id, sometimes with a regexp -- searched every term over the
whole branch and intersected the results, so the session term returned every
document of the session and the regexp tested every document.
Ported from DID-matlab#229 (dae960b..83a2bda):
- _search_doc_ids searches the terms of an AND in rank order: base.id
lookups, other terms, base.session_id, then terms that test every value
(regexp, contains_string, hasmember, and the brute-force operations). It
stops at the first term that matches nothing, and once the result is down
to 1000 documents checks later terms against those only
(docs.doc_id IN (...), CROSS JOIN order, INDEXED BY doc_data_doc_idx).
A brute-force term given candidates loads only those documents.
- ORed base.id lookups, nested to any depth, are one query per 1000 ids
(_search_base_ids, _base_id_lookup_values).
- Unrestricted 'isa' runs its regexp on the distinct superclass lists only,
read from doc_data_field_value, instead of on every document.
- _ensure_indexes now records whether the doc_data indexes exist
(_search_indexes_ready) and leaves a database it cannot write to without
them, where it used to fail to open; searches there run as before.
DID-matlab now creates the same indexes under the same names.
Synthetic database, 100,000 documents / 3M doc_data rows, main -> this:
base.id AND session 0.177 s -> 0.0001 s
OR of 9 ids AND session 0.181 s -> 0.0006 s
isa daqsystem AND session 0.299 s -> 0.027 s
isa AND session AND regexp 0.603 s -> 0.027 s
Tests: tests/test_search_indexes.py (mirrors DID-matlab's
TestSearchIndexes). Bridge: sqlitedb and database entries -> 83a2bda.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dv7SxVR8MCu3MKpUvwwUia1 parent d84921c commit 3acc58e
4 files changed
Lines changed: 683 additions & 41 deletions
File tree
- src/did
- implementations
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
49 | 60 | | |
50 | 61 | | |
51 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
39 | 58 | | |
40 | 59 | | |
41 | 60 | | |
| |||
0 commit comments