Query a 4 GB CSV
in 1.7 ms
A secondary index for huge CSV files. The CSV stays exactly as it is — a flat, hash-ordered index sits beside it. No import, no duplicate, no database.
One user’s orders, out of 100 million rows
The index reads only the 8 rows that match. Everything else on this chart reads the whole file.
100M rows, 4.18 GiB, warm cache, key matching 8 rows. Same file, same query. From Python it is idx.get(user_id) → a pandas DataFrame; numbers verified against grep row counts. Honest edge: a key with 2% of the file loses to DuckDB on a cold cache — the index pays off while the query takes a small share of rows.
Build once, query forever
Appends are cheap too: new rows go to a small tail file, the main index is never rewritten.
A flat array, sorted by hash
No tree, no page structure to maintain. Record i lives at byte 64 + 16·i, so binary search over the mmap is the whole story.
- Binary search over mmap
Nothing is loaded on open — the index opens in ~0.1 ms and pages come in as the search touches them.
- Appends go to a tail
.idx.tail — new rows land in a small side file; compact merges it in 3 s when it reaches 10%.
- A fence for cold caches
.idx.fence — first hash of every 4 KiB page, one page read per query instead of ~20.
- Fixed-memory builds
External sort: the same index byte-for-byte from 64 MiB of RAM to all-in-memory.
The rows you asked for, as a DataFrame
Column types come from the found rows via pd.read_csv, so results match read_csv + a filter. Lookups release the GIL and run in parallel.
What it does not do
Edits in the middle of the file are not detected. Suspect edits — run csvidx verify.
Byte-for-byte: "007" ≠ 7. Ranges are impossible — the index is ordered by hash.
A query returning a few percent of the file is random reads; a scan wins past that point.