File Index
Configure file-index.${index_type}.columns to build indexes for selected columns in each data
file. A file index can contain multiple index types and columns. Small indexes can be embedded
in the manifest; larger indexes are stored alongside the data file.
This page describes the binary layout. For query-planning guidance, see Query Performance. For dynamic bucket indexes and deletion vectors, see Table Index.
| Encoding | Section |
|---|---|
| Shared header and column offsets | Index File |
| Bloom filter | BloomFilter |
| Bitmap | Bitmap |
| Range bitmap | Range Bitmap |
| Bit-slice bitmap | Bit-Slice Index Bitmap |
Index File
File index file format. Put all column and offset in the header.
| magic |version|head length |
|---|
| column number |
| -------------------------------------- |
| column 1 | index number |
| -------------------------------------- |
| index name 1 |start pos |length |
| -------------------------------------- |
| index name 2 |start pos |length |
| -------------------------------------- |
| index name 3 |start pos |length |
| -------------------------------------- |
| column 2 | index number |
| -------------------------------------- |
| index name 1 |start pos |length |
| -------------------------------------- |
| index name 2 |start pos |length |
| -------------------------------------- |
| index name 3 |start pos |length |
| -------------------------------------- |
| ... |
| -------------------------------------- |
| ... |
| -------------------------------------- |
| redundant length |redundant bytes |
| -------------------------------------- |
| BODY |
| BODY |
| BODY |
| BODY |
| ______________________________________ |
magic: 8 bytes long, value is 1493475289347502L, BIG_ENDIAN version: 4 bytes int, BIG_ENDIAN head length: 4 bytes int, BIG_ENDIAN column number: 4 bytes int, BIG_ENDIAN column x name: var bytes, Java modified-utf-8 index number: 4 bytes int (how many column items below), BIG_ENDIAN index name x: var bytes, Java modified-utf-8 start pos: 4 bytes int, BIG_ENDIAN length: 4 bytes int, BIG_ENDIAN redundant length: 4 bytes int (for compatibility with later versions, in this version, content is zero) redundant bytes: var bytes (for compatibility with later version, in this version, is empty) BODY: column index bytes + column index bytes + column index bytes + .......
Index: BloomFilter
Options are:
file-index.bloom-filter.columns: specify the columns that need bloom filter index.file-index.bloom-filter.<column_name>.fppto config false positive probability.file-index.bloom-filter.<column_name>.itemsto config the expected distinct items in one data file.
Content of bloom filter index is simple:
- numHashFunctions 4 bytes int, BIG_ENDIAN
- bloom filter bytes
This class use (64-bits) long hash. Store the num hash function (one integer) and bit set bytes only. Hash bytes type (like varchar, binary, etc.) using xx hash, hash numeric type by specified number hash.
BloomFilter supports the following data types:
| Data type | Hash function |
|---|---|
CharType, VarCharType | xx hash (64-bit) |
BinaryType, VarBinaryType | xx hash (64-bit) |
TinyIntType, SmallIntType, IntType, BigIntType | Thomas Wang hash |
FloatType, DoubleType | Thomas Wang hash (on IEEE 754 bit representation) |
DateType, TimeType, TimestampType, LocalZonedTimestampType | Thomas Wang hash |
BloomFilter does not support: BooleanType, DecimalType, VariantType, BlobType, ArrayType, VectorType, MultisetType, MapType, RowType.
Index: Bitmap
file-index.bitmap.columns: specify the columns that need bitmap index.file-index.bitmap.<column_name>.index-block-size: to config secondary index block size, default value is 16kb.
- V2
- V1 (Legacy)
Bitmap file index format (V2):
Bitmap file index format (V2) +-------------------------------------------------+----------------- | version (1 byte) = 2 | +-------------------------------------------------+ | row count (4 bytes int) | +-------------------------------------------------+ | non-null value bitmap number (4 bytes int) | +-------------------------------------------------+ | has null value (1 byte) | +-------------------------------------------------+ | null value offset (4 bytes if has null value) | HEAD +-------------------------------------------------+ | null bitmap length (4 bytes if has null value) | +-------------------------------------------------+ | bitmap index block number (4 bytes int) | +-------------------------------------------------+ | value 1 | offset 1 | +-------------------------------------------------+ | value 2 | offset 2 | +-------------------------------------------------+ | ... | +-------------------------------------------------+ | bitmap body offset (4 bytes int) | +-------------------------------------------------+----------------- | bitmap index block 1 | +-------------------------------------------------+ | bitmap index block 2 | INDEX BLOCKS +-------------------------------------------------+ | ... | +-------------------------------------------------+----------------- | serialized bitmap 1 | +-------------------------------------------------+ | serialized bitmap 2 | +-------------------------------------------------+ BITMAP BLOCKS | serialized bitmap 3 | +-------------------------------------------------+ | ... | +-------------------------------------------------+-----------------
index block format: +-------------------------------------------------+ | entry number (4 bytes int) | +-------------------------------------------------+ | value 1 | offset 1 | length 1 | +-------------------------------------------------+ | value 2 | offset 2 | length 2 | +-------------------------------------------------+ | ... | +-------------------------------------------------+
value x: var bytes for any data type (as bitmap identifier) offset: 4 bytes int; a negative offset encodes a single row position as -offset - 1 length: 4 bytes int
(Legacy) Bitmap file index format (V1):
You can configure file-index.bitmap.<column_name>.version to use legacy bitmap version 1.
Bitmap file index format (V1) +-------------------------------------------------+----------------- | version (1 byte) | +-------------------------------------------------+ | row count (4 bytes int) | +-------------------------------------------------+ | non-null value bitmap number (4 bytes int) | +-------------------------------------------------+ | has null value (1 byte) | +-------------------------------------------------+ | null value offset (4 bytes if has null value) | HEAD +-------------------------------------------------+ | value 1 | offset 1 | +-------------------------------------------------+ | value 2 | offset 2 | +-------------------------------------------------+ | value 3 | offset 3 | +-------------------------------------------------+ | ... | +-------------------------------------------------+----------------- | serialized bitmap 1 | +-------------------------------------------------+ | serialized bitmap 2 | +-------------------------------------------------+ BODY | serialized bitmap 3 | +-------------------------------------------------+ | ... | +-------------------------------------------------+----------------- * value x: var bytes for any data type (as bitmap identifier) offset: 4 bytes int; a negative offset encodes a single row position as -offset - 1
Integers are all BIG_ENDIAN.
Bitmap supports boolean, integer, floating-point, character-string, date, time, and timestamp
types, including local-zoned timestamps. STRING uses the VarCharType representation.
Index: Range Bitmap
Advantage:
- Smaller than the bitmap index.
- Suitable for the point query and the range query in the high level of cardinality scenarios.
- Can be used to optimize the AND/OR predicates. (The corresponding columns need to have either bitmap index or range-bitmap index.)
- Can be used to optimize the topk/bottomk query. (Currently only suitable for append-only tables.)
Shortcoming:
- The point query evaluation maybe slower than bitmap index.
Options:
file-index.range-bitmap.columns: specify the columns that need range-bitmap index.file-index.range-bitmap.<column_name>.chunk-size: dictionary chunk size. The default is16kbfor most supported types;BooleanType,TinyIntType, andSmallIntTypedefault to0b.
Table supports using range-bitmap file index to optimize the EQUALS, RANGE, AND/OR and TOPN predicate. The bitmap and range-bitmap file index result will be merged and pushed down to the DataFile for filtering rowgroups and pages.
In the following query examples, the class_id and the score has been created with range-bitmap file index. And the partition key dt is not necessary.
Optimize the EQUALS predicate:
SELECT * FROM TABLE WHERE dt = '20250801' AND score = 100;
SELECT * FROM TABLE WHERE dt = '20250801' AND score IN (60, 80);
Optimize the RANGE predicate:
SELECT * FROM TABLE WHERE dt = '20250801' AND score > 60;
SELECT * FROM TABLE WHERE dt = '20250801' AND score < 60;
Optimize the AND/OR predicate:
SELECT * FROM TABLE WHERE dt = '20250801' AND class_id = 1 AND score < 60;
SELECT * FROM TABLE WHERE dt = '20250801' AND class_id = 1 AND score < 60 OR score > 80;
Optimize the TOPN predicate:
For now, the TOPN predicate optimization can not use with other predicates, only support in Apache Spark.
SELECT * FROM TABLE WHERE dt = '20250801' ORDER BY score ASC LIMIT 10;
SELECT * FROM TABLE WHERE dt = '20250801' ORDER BY score DESC LIMIT 10;
-- if there are multiple sort keys, the first sort key must be created with range-bitmap.
SELECT * FROM TABLE WHERE dt = '20250801' ORDER BY score ASC, col DESC LIMIT 10;
SELECT * FROM TABLE WHERE dt = '20250801' ORDER BY score DESC, col ASC LIMIT 10;
Range Bitmap file index format (V1) +-------------------------------------------------+----------------- | header length (4 bytes int) | +-------------------------------------------------+ | version (1 byte) | +-------------------------------------------------+ | row number (4 bytes int) | +-------------------------------------------------+ | cardinality (4 bytes int) | HEAD +-------------------------------------------------+ | min value (only when cardinality > 0) | +-------------------------------------------------+ | max value (only when cardinality > 0) | +-------------------------------------------------+ | dictionary length (4 bytes int) | +-------------------------------------------------+----------------- | dictionary serialize in bytes | +-------------------------------------------------+ BODY | bit-slice index bitmap serialize in bytes | +-------------------------------------------------+-----------------
Dictionary format (V1) +-------------------------------------------------+----------------- | header length (4 bytes int) | +-------------------------------------------------+ | version (1 byte) | +-------------------------------------------------+ | the chunks size (4 bytes int) | HEAD +-------------------------------------------------+
| the offsets length (4 bytes int) |
+-------------------------------------------------+ | the chunks length (4 bytes int) | +-------------------------------------------------+----------------- | offsets serialize in bytes | +-------------------------------------------------+ | chunks serialize in bytes | BODY +-------------------------------------------------+ | keys serialize in bytes | +-------------------------------------------------+-----------------
Bit-slice index bitmap format (V1) +-------------------------------------------------+----------------- | header length (4 bytes int) | +-------------------------------------------------+ | version (1 byte) | +-------------------------------------------------+ | slices size (1 byte) | HEAD +-------------------------------------------------+
| existence bitmap length (4 bytes int) |
+-------------------------------------------------+ | indexes length (4 bytes int) | +-------------------------------------------------+ | indexes serialize in bytes | +-------------------------------------------------+----------------- | existence bitmap serialize in bytes | +-------------------------------------------------+ | the bit 0 bitmap serialize in bytes | +-------------------------------------------------+ | the bit 1 bitmap serialize in byte | BODY +-------------------------------------------------+ | the bit 2 bitmap serialize in byte | +-------------------------------------------------+ | ... | +-------------------------------------------------+-----------------
RangeBitmap supports the following logical types:
| Type family | Supported types and limits |
|---|---|
| Boolean and integers | BOOLEAN, TINYINT, SMALLINT, INT, BIGINT |
| Floating point | FLOAT, DOUBLE |
| Decimal | DECIMAL with precision at most 18 |
| Character strings | CHAR, VARCHAR, STRING |
| Date and time | DATE, TIME |
| Timestamps | TIMESTAMP and local-zoned TIMESTAMP with precision at most 6 |
Index: Bit-Slice Index Bitmap
Deprecated. Using the range-bitmap index instead.
BSI file index is a numeric range index, used to accelerate range query, it can be used with bitmap index.
Define 'file-index.bsi.columns'.
BSI file index format (V1):
BSI file index format (V1) +-------------------------------------------------+ | version (1 byte) | +-------------------------------------------------+ | row count (4 bytes int) | +-------------------------------------------------+ | has positive value (1 byte) | +-------------------------------------------------+ | positive BSI serialized (if has positive value) |
+-------------------------------------------------+ | has negative value (1 byte) | +-------------------------------------------------+ | negative BSI serialized (if has negative value) |
+-------------------------------------------------+
BSI serialized format (V1):
BSI serialized format (V1) +-------------------------------------------------+ | version (1 byte) | +-------------------------------------------------+ | min value (8 bytes long) | +-------------------------------------------------+ | max value (8 bytes long) | +-------------------------------------------------+ | serialized existence bitmap |
+-------------------------------------------------+ | bit slice bitmap count (4 bytes int) | +-------------------------------------------------+ | serialized bit 0 bitmap | +-------------------------------------------------+ | serialized bit 1 bitmap | +-------------------------------------------------+ | serialized bit 2 bitmap | +-------------------------------------------------+ | ... | +-------------------------------------------------+
Legacy BSI supports integer, date, time, timestamp (including local-zoned timestamp), and decimal types. A decimal's unscaled value must fit in a signed 64-bit integer. Use Range Bitmap for new indexes.