1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2025 Stoolap Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Frozen Volume Storage
//!
//! A frozen volume is an immutable, column-major storage unit for historical data.
//! It is the on-disk counterpart to the in-memory arena (hot buffer).
//!
//! # Architecture
//!
//! ```text
//! Table
//! ├── Hot Buffer (in-memory VersionStore + Arena)
//! │ └── Current writes, full MVCC, WAL-protected
//! │
//! ├── Volume 0 (frozen, on disk)
//! │ ├── Column data (typed arrays per column)
//! │ ├── String dictionary (deduplicated text values)
//! │ ├── Zone maps (min/max per column for pruning)
//! │ ├── Pre-computed aggregate stats
//! │ └── Visibility bitmap (for logical deletes)
//! │
//! ├── Volume 1 (frozen, on disk)
//! │ └── ...
//! │
//! └── Volume Catalog (tiny metadata file)
//! ```
//!
//! # Design Principles
//!
//! - **Column-major**: Each column stored contiguously for cache-friendly scans.
//! A query reading 2 of 9 columns reads 22% of the data, not 100%.
//! - **Typed arrays**: Integer/Float/Timestamp columns stored as raw i64/f64 arrays.
//! No per-value type tag, no enum overhead during scans.
//! - **Dictionary encoding**: Text columns store u32 IDs referencing a deduplicated
//! string table. Repeated values (e.g., exchange names) use 4 bytes instead of N.
//! - **Zone maps**: Per-column min/max enables skipping entire volumes for range
//! predicates. `WHERE time >= X` can skip volumes without reading any data.
//! - **Pre-computed stats**: COUNT, SUM, MIN, MAX, AVG stored per column at freeze
//! time. Common aggregation queries return instantly with zero row scanning.
//! - **Binary search**: Sorted columns (typically time) support O(log n) range
//! lookups instead of linear scan.
//! - **Platform independent**: The format is a byte layout. Access methods
//! (mmap on native, buffered I/O, or Vec<u8> on WASM) are behind a trait.
//! - **Backward compatible**: Memory mode uses no volumes. Persistence mode
//! uses hot buffer + frozen volumes. The executor sees the same Table/Scanner
//! traits regardless.