index/inverted_index/
format.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! # SST Files with Inverted Index Format Specification
16//!
17//! ## File Structure
18//!
19//! Each SST file includes a series of inverted indices followed by a footer.
20//!
21//! `inverted_index₀ inverted_index₁ ... inverted_indexₙ footer`
22//!
23//! - Each `inverted_indexᵢ` represents an index entry corresponding to tag values and their locations within the file.
24//! - `footer`: Contains metadata about the inverted indices, encoded as a protobuf message.
25//!
26//! ## Inverted Index Internals
27//!
28//! An inverted index comprises a collection of bitmaps, a null bitmap, and a finite state transducer (FST) indicating tag values' positions:
29//!
30//! `null_bitmap bitmap₀ bitmap₁ bitmap₂ ... bitmapₙ fst`
31//!
32//! - `null_bitmap`: Bitset tracking the presence of null values within the tag column.
33//! - `bitmapᵢ`: Bitset indicating the presence of tag values within a row group.
34//! - `fst`: Finite State Transducer providing an ordered map of bytes, representing the tag values.
35//!
36//! ## Footer Details
37//!
38//! The footer encapsulates the metadata for inversion mappings:
39//!
40//! `footer_payload footer_payload_size`
41//!
42//! - `footer_payload`: Protobuf-encoded [`InvertedIndexMetas`] describing the metadata of each inverted index.
43//! - `footer_payload_size`: Size in bytes of the `footer_payload`, displayed as a `u32` integer.
44//! - The footer aids in the interpretation of the inverted indices, providing necessary offset and count information.
45//!
46//! ## Reference
47//!
48//! More detailed information regarding the encoding of the inverted indices can be found in the [RFC].
49//!
50//! [`InvertedIndexMetas`]: https://github.com/GreptimeTeam/greptime-proto/blob/2aaee38de81047537dfa42af9df63bcfb866e06c/proto/greptime/v1/index/inverted_index.proto#L32-L64
51//! [RFC]: https://github.com/GreptimeTeam/greptimedb/blob/main/docs/rfcs/2023-11-03-inverted-index.md
52
53pub mod reader;
54pub mod writer;
55
56const FOOTER_PAYLOAD_SIZE_SIZE: u64 = 4;
57const MIN_BLOB_SIZE: u64 = FOOTER_PAYLOAD_SIZE_SIZE;