You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/reference/c.md
+67Lines changed: 67 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -625,6 +625,73 @@ if (tidesdb_get_cache_stats(db, &cache_stats) == 0)
625
625
The block cache is a database-level resource shared across all column families. It caches deserialized klog blocks to avoid repeated disk I/O and deserialization. Configure cache size via `config.block_cache_size` when opening the database. Set to 0 to disable caching.
626
626
:::
627
627
628
+
### Range Cost Estimation
629
+
630
+
`tidesdb_range_cost` estimates the computational cost of iterating between two keys in a column family. The returned value is an opaque double — meaningful only for comparison with other values from the same function. It uses only in-memory metadata and performs no disk I/O.
The function walks all SSTable levels and uses in-memory metadata to estimate how many blocks and entries fall within the given key range:
675
+
676
+
- With block indexes enabled · Uses O(log B) binary search per overlapping SSTable to find the block slots containing each key bound. The block span between slots, scaled by `index_sample_ratio`, gives the estimated block count.
677
+
- Without block indexes · Falls back to byte-level key interpolation. The leading 8 bytes of each key are converted to a numeric position within the SSTable's min/max key range to estimate the fraction of blocks covered.
678
+
- B+tree SSTables (`use_btree=1`) · Uses the same key interpolation against tree node counts, plus tree height as a seek cost. Only applies to column families configured with B+tree klog format.
679
+
- Compression · Compressed SSTables receive a 1.5× weight multiplier to account for decompression overhead.
680
+
- Merge overhead · Each overlapping SSTable adds a small fixed cost for merge-heap operations.
681
+
- Memtable · The active memtable's entry count contributes a small in-memory cost.
682
+
683
+
Key order does not matter — the function normalizes the range so `key_a > key_b` produces the same result as `key_b > key_a`.
684
+
685
+
**Use cases**
686
+
- Query planning · Compare candidate key ranges to find the cheapest one to scan
687
+
- Load balancing · Distribute range scan work across threads by estimating per-range cost
688
+
- Adaptive prefetching · Decide how aggressively to prefetch based on range size
689
+
- Monitoring · Track how data distribution changes across key ranges over time
690
+
691
+
:::note[Cost Values]
692
+
The returned cost is not an absolute measure (it does not represent milliseconds, bytes, or entry counts). It is a relative scalar — only meaningful when compared with other `tidesdb_range_cost` results. A cost of 0.0 means no overlapping SSTables or memtable entries were found for the range.
693
+
:::
694
+
628
695
### Compression Algorithms
629
696
630
697
TidesDB supports multiple compression algorithms to reduce storage footprint and I/O bandwidth. Compression is applied to both klog (key-log) and vlog (value-log) blocks before writing to disk.
0 commit comments