Column Projections, the Time Series Store and Parquet
This chapter covers three pieces of storage code that are often grouped together because they deal with analytic or time-ordered data:
- Column projections: an in-memory, column-at-a-time view of an SSTable range that the query engine uses for scans and simple aggregates. Nothing is stored on disk in a column format.
-
The time series store (
src/storage/timeseries/): a bucketed point store over the key-value engine. Today it is used only by the InfluxDB wire, as a legacy layout it reads at start-up. -
Parquet: there are two Parquet code paths. The real one reads and writes Parquet files for Snowflake stages, using the third-party
parquetandarrowcrates. The other,src/storage/parquet/, is an unfinished hand-written format that nothing calls.
SSTable layout, block flags and readers are described in SSTable format; the general key layout is in Keys and namespaces.
Column projections
What a projection is
A projection (ColumnChunk) is built from one SSTable reader and one key range [lo, hi). It holds the newest version of each user key in that range, laid out by column. The on-disk SSTable format does not change; the projection is decoded from ordinary data blocks found with block_handles_in (source: src/storage/columnar.rs, ColumnChunk::build_within; src/storage/sst.rs, SSTableReader::block_handles_in).
| Field | Contents |
|---|---|
keys, key_ends
|
All user keys concatenated, with end offsets |
seqs |
Sequence number of the version kept for each row |
deleted, deleted_rows
|
Per-row tombstone flag, and the sorted list of deleted row numbers |
locs, handles
|
Where each row's value sits (block, entry), so a full row can be decoded on demand |
cols |
One Column per cell position: Column::Int { vals, valid } for integer cells, Column::Other for anything else |
min_cells |
Smallest cell count seen in any row |
bytes |
Running size estimate used for the cache budget |
max_ts |
Largest write timestamp in the range, used by AS OF scans |
(source: src/storage/columnar.rs, ColumnChunk, Column)
Accessors are find and lower_bound (binary search on keys), int_col (an integer column's values and validity), with_row (decode one row's full value) and deleted_in (source: src/storage/columnar.rs, ColumnChunk::find, ColumnChunk::int_col, ColumnChunk::with_row).
Building
build_within walks the blocks of the range in key order and keeps only the newest version of each user key. It returns None (meaning "use the row path instead") when keys arrive out of order or a key cannot be parsed, or when the estimated size would exceed the byte budget passed in. Decoded blocks are dropped as soon as no remaining row can point into them (source: src/storage/columnar.rs, ColumnChunk::build_within).
Each row's value is decoded by push_row, which reads the row's cell tags. Only integer cells become typed columns; every other tag is skipped by its size so later cells can still be found. An unknown tag stops decoding for that row (source: src/storage/columnar.rs, ColumnChunk::push_row).
| Cell tag | Bytes skipped or read | Column type |
|---|---|---|
| 0 | 0 (NULL) | NULL in an integer column |
| 1 | 1 | Other |
| 2 | 1 | Int (i8) |
| 3 | 2 | Int (i16) |
| 4 | 4 | Int (i32) |
| 5, 6 | 8 | Int (i64) |
| 7, 14 | 4 | Other |
| 8, 9, 13, 15 | 8 | Other |
| 10 | 17 | Other |
| 11, 12 | length-prefixed | Other |
| any other | decoding of the row stops |
(source: src/storage/columnar.rs, ColumnChunk::push_row)
The size estimate grows by the key bytes, plus 21 bytes per row, plus 9 bytes per row for each integer column (source: src/storage/columnar.rs, ColumnChunk::push_row).
The projection cache
Projections are kept in one process-wide cache, evicted least-recently-used by bytes. The key is the SSTable reader id plus lo, a zero byte and hi; reader ids are unique per open reader (see SSTable format). A range that cannot be built is cached as None, so later scans of the same file go straight to the row path (source: src/storage/columnar.rs, chunk_for, cache).
overlap_masks computes, for two projections over the same range, which rows of each are superseded by a newer row or delete in the other. Results are cached per pair of SSTables; the mask map is cleared when it reaches 64 entries (source: src/storage/columnar.rs, overlap_masks).
| Setting | Default | Effect | Source |
|---|---|---|---|
SYNERGYDB_COLUMN_CACHE_MB |
512 | Byte budget of the projection cache, read once. 0 disables projections entirely |
src/storage/columnar.rs, cache
|
SYNERGYDB_COLUMNAR_MIN_SST_BYTES |
4 MiB | SSTables smaller than this are not projected and are merged as rows. Read once |
src/storage/mod.rs, columnar_min_sst_bytes
|
StorageEngine::set_columnar_min_sst_bytes |
n/a | Overrides the threshold for one engine (used by tests) |
src/storage/mod.rs, StorageEngine::set_columnar_min_sst_bytes
|
Columnar scans
StorageEngine::scan_columnar and scan_columnar_as_of call scan_columnar_min, which returns a list of ColumnarPart values in key order (source: src/storage/mod.rs, StorageEngine::scan_columnar_min, ColumnarPart):
-
ColumnarPart::Rows { chunk, reader, rows, key_skip }for a projected SSTable, with the row numbers still visible after masking. -
ColumnarPart::Row { key, value }for a row from a small SSTable or a memtable.
(source: src/storage/mod.rs, StorageEngine::scan_columnar_min, StorageEngine::rotate_for_columns)
The whole call declines (returns None) if any large SSTable cannot be projected, or for an AS OF scan when a projection holds a write newer than the requested time. Overlapping projections are not declined: they are masked with overlap_masks. The doc comment on scan_columnar still says overlapping SSTables make it decline; the code masks instead (source: src/storage/mod.rs, StorageEngine::scan_columnar, StorageEngine::scan_columnar_min).
When the row-form part of a scan is large (at least 65,536 rows and at least one eighth of the projected rows), the engine rotates the memtable so a later flush can turn those rows into a projectable SSTable. This happens at most once every 5 seconds. Each columnar scan increments the COLUMNAR_SCANS counter (source: src/storage/mod.rs, StorageEngine::rotate_for_columns, COLUMNAR_SCANS).
Tested by columnar_scan_matches_row_scan and column_scan_hands_a_memtable_heavy_range_to_the_flush in src/storage/mod.rs (scan_merge_tests), and by test_columnar_aggregates_match_general_path in src/query/engine.rs.
Who uses projections
The SQL engine uses columnar scans in three places: pre-filtered scans, typed simple aggregates and typed top-k. All three only take the fast path for integer columns; anything else goes through the row path (source: src/query/engine.rs, scan_prefiltered, try_typed_simple_aggregate, try_typed_top_k).
The time series store
Data model
| Type | Fields |
|---|---|
DataPoint |
timestamp (milliseconds), value (f64), quality (u8) |
SeriesMetadata |
series id, metric name, tags, plus running statistics |
TimeSeriesBucket |
series id, granularity, bucket start, sorted points |
TimeBucket |
Minute (60 s), Hour, Day, Week, Month (fixed 30 days) |
(source: src/storage/timeseries/mod.rs, DataPoint, SeriesMetadata, TimeSeriesBucket, TimeBucket::duration)
A series is identified by the metric name plus its tags sorted by key (metric;k1=v1;k2=v2). Series ids are assigned from a counter that load sets to one more than the highest stored id (source: src/storage/timeseries/mod.rs, TimeSeriesStore::metric_index_key, TimeSeriesStore::get_or_create_series, TimeSeriesStore::load).
Keys
| Key | Value |
|---|---|
__ts__:meta:{series_id:016x} |
SeriesMetadata, bincode |
__ts__:data:{series_id:016x}:{Granularity}:{bucket_start:016x} |
TimeSeriesBucket, bincode. Granularity is the enum's debug name, for example Minute. bucket_start is in seconds |
__ts__:ds:{series_id:016x}:{Granularity}:{bucket_start:016x} |
Downsampled points |
__ts__:retention:policy:{name} |
Retention policy |
(source: src/storage/timeseries/mod.rs, TimeSeriesStore::get_or_create_series, TimeSeriesStore::flush_points; src/storage/timeseries/downsampling.rs; src/storage/timeseries/retention.rs)
Configuration
TimeSeriesConfig field |
Default |
|---|---|
default_granularity |
Minute |
max_buffer_size |
10,000 points |
buffer_flush_interval |
60 s |
| downsampling rules | Minute to Hour after 7 days; Hour to Day after 30 days; Day to Week after 365 days |
| retention | enabled, default retention 0 (keep forever) |
max_out_of_order |
0 (unlimited) |
(source: src/storage/timeseries/mod.rs, TimeSeriesConfig::default)
Write and read paths
Writes go to a WriteBuffer. When it is full, or on an explicit flush, flush_points groups points by bucket, reads each existing bucket, merges the new points, and writes all buckets in one write_batch. If an existing bucket fails to decode, it is silently replaced by a new one. There is no timer: buffer_flush_interval is only checked when a write arrives (source: src/storage/timeseries/mod.rs, TimeSeriesStore::write_to_series, TimeSeriesStore::flush_points, TimeSeriesStore::flush). If the buffer already holds a point with the same timestamp, the existing point is kept when its quality number is less than or equal to the new one's (a lower number ranks as better) (source: src/storage/timeseries/buffer.rs, WriteBuffer::add). Tested by test_write_buffer_add, test_write_buffer_out_of_order, test_write_buffer_reject_old, test_ring_buffer, test_compaction_buffer in buffer.rs.
Metadata is written once when a series is created; later statistics updates stay in the in-memory cache (source: src/storage/timeseries/mod.rs, TimeSeriesStore::get_or_create_series, SeriesMetadata::update).
Known defect, Not verified: flush_points computes bucket_start from timestamp / 1000 (seconds), but query_series computes the start and end bucket from the millisecond arguments without dividing by 1000. A query over a narrow millisecond range therefore scans bucket keys that are 1000 times too large and misses stored data. The only production caller passes the range 0..9_999_999_999_999, which covers every stored bucket, so it is not affected. No test covers query_series (source: src/storage/timeseries/mod.rs, TimeSeriesStore::flush_points, TimeSeriesStore::query_series).
Retention and downsampling
retention.rs holds named policies matched by metric pattern; cut-offs are computed in seconds. downsampling.rs aggregates buckets into coarser granularities (source: src/storage/timeseries/retention.rs, RetentionManager; src/storage/timeseries/downsampling.rs, Downsampler). Unit tests: test_retention_policy_matching, test_pattern_matching, test_policy_builder, test_cutoff_calculation, test_aggregate_functions, test_percentile, test_downsampled_point, test_aggregate_by_bucket.
Not wired: TimeSeriesStore::run_retention and TimeSeriesStore::run_downsampling have no callers, so neither retention nor downsampling ever runs on stored data (source: src/storage/timeseries/mod.rs, TimeSeriesStore::run_retention, TimeSeriesStore::run_downsampling).
Who uses it
The only production user is the InfluxDB handler. with_storage builds a store with max_buffer_size 1024 and buffer_flush_interval 1, calls load, and rebuilds its bucket catalog from the stored series. load_legacy reads old points with query_series over the full range. Current InfluxDB writes do not go through TimeSeriesStore; they use the handler's own per-point records written with StorageEngine::write_batch. In practice the time series store is the older layout that the InfluxDB wire reads at start-up (source: src/protocol/influxdb/mod.rs, InfluxDbHandler::with_storage, populate_catalog_from_store, load_legacy). See InfluxDB for the wire itself.
Module unit tests: test_time_bucket_duration, test_time_bucket_start, test_metric_index_key, test_series_metadata in src/storage/timeseries/mod.rs.
Parquet
Cargo feature parquet
Cargo.toml declares parquet = []. The feature gates nothing: no cfg(feature = "parquet") appears in the source. The third-party crates parquet (version 53, imported under the name parquet_rs, with the arrow, snap, flate2 and zstd features) and arrow (version 53) are ordinary dependencies and are compiled in every build (source: Cargo.toml, [features], [dependencies]).
Real Parquet I/O: Snowflake stages
All Parquet that users can read or write goes through the Snowflake stage code (source: src/protocol/snowflake/stage.rs, parse_parquet, write_parquet).
Reading. parse_parquet opens the file with ParquetRecordBatchReaderBuilder from the parquet crate and turns each row into a JSON object (a Snowflake VARIANT). A column named __index_level_0__ (a pandas index) is skipped. It is used by COPY INTO <table>, by SELECT ... FROM @stage, and by INFER_SCHEMA (source: src/protocol/snowflake/stage.rs, parse_parquet).
Writing. COPY INTO @stage ... FILE_FORMAT = (TYPE = PARQUET) calls write_parquet, which maps result column types to Arrow types:
| Result type | Arrow type written |
|---|---|
NUMBER(38,0) |
Decimal128(38, 0) |
NUMBER(p,s) |
Decimal128(p, s) |
FLOAT, DOUBLE
|
Float64 |
DATE |
Date32 |
TIMESTAMP_NTZ |
Timestamp (milliseconds) |
BOOLEAN |
Boolean |
| anything else | Utf8 |
Columns are named _COL_0, _COL_1, and so on; pages are compressed with Snappy; files get the extension .snappy.parquet (source: src/protocol/snowflake/stage.rs, write_parquet).
There is no unit test for either function in stage.rs. The stage differential suite against Snowflake scored 79 of 85 on 2026-11-30; one of the remaining differences is how a Parquet float prints when read back (2.5 against Snowflake's 2.500000000000000e+00) (source: docs/status/2026-11-30-snowflake-stages.md). See Snowflake.
Migration has no Parquet source; see Migration.
src/storage/parquet/: unfinished, not used
Not wired: the storage::parquet module (mod.rs, encoding.rs, reader.rs, schema.rs, writer.rs) has no caller outside itself (source: src/storage/parquet/mod.rs, ParquetHandler).
It is not standard Parquet. The writer puts the PAR1 magic around a custom little-endian footer (version, row count, field names) instead of the Thrift FileMetaData; comments in the writer say Thrift would be used "in production". The reader's parse_footer returns an empty schema and no row groups, and read_page_header expects a fixed 24-byte custom header. Files written by it cannot be read by other Parquet tools, and it cannot read files written by them (source: src/storage/parquet/writer.rs, ParquetWriter; src/storage/parquet/reader.rs, parse_footer, read_page_header).
| Constant or type | Value | Source |
|---|---|---|
DEFAULT_PAGE_SIZE |
1 MB | src/storage/parquet/mod.rs |
DEFAULT_ROW_GROUP_SIZE |
128 MB | src/storage/parquet/mod.rs |
Compression default |
Snappy |
src/storage/parquet/mod.rs |
Compression codes |
Snappy 1, Gzip 2, Lz4 3, Lz4Raw 4, Zstd 5 | src/storage/parquet/mod.rs |
ParquetHandler |
export_table, import_file
|
src/storage/parquet/mod.rs |
The module has its own unit tests (3 in mod.rs, 5 in encoding.rs, 5 in schema.rs, 2 in reader.rs, 3 in writer.rs). Not verified: no test reads its output with another Parquet implementation, and no integration test exercises it.