Skip to content

Integrate FastPFor as posting list codec - #95517

Closed
fastio wants to merge 0 commit into
ClickHouse:masterfrom
fastio:integration_codec_for_text_index
Closed

fastio wants to merge 0 commit into
ClickHouse:masterfrom
fastio:integration_codec_for_text_index

Conversation

@fastio

@fastio fastio commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add FastPFor family of posting list compression codecs for text indexes: fastpfor, binarypacking, simple8b, streamvbyte, and optpfor. These SIMD-accelerated codecs provide various compression ratio vs decode speed trade-offs for full-text search workloads.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Motivation

Text indexes store posting lists (lists of row IDs containing each token). For large tables, these posting lists can become very large and benefit significantly from compression. Previously, only bitpacking and none codecs were available. This PR adds five additional high-performance codecs from the FastPFor library, each optimized for different use cases.

New Posting List Codecs

Codec Compression Decode Speed Best For
fastpfor High Very Fast General-purpose (recommended)
binarypacking Medium Fastest Query latency-critical scenarios
optpfor Highest Fast Storage-constrained scenarios

All codecs use SIMD acceleration (SSE/AVX on x86_64, SIMDE on ARM64) for optimal performance.

Parameters

New option for text index creation:

  • posting_list_codec: Specifies the compression algorithm for posting lists
    • Allowed values: 'none'(default), 'bitpacking' , 'fastpfor', 'binarypacking', 'optpfor'
    • FastPFor codecs require the FastPFor library (not available in fasttest builds)

Example Usage

-- Create a text index with FastPFor compression
CREATE TABLE logs
(
    ts DateTime,
    message String,
    INDEX idx_message message TYPE text(
        tokenizer = 'splitByNonAlpha',
        posting_list_codec = 'fastpfor'
    )
)
ENGINE = MergeTree
ORDER BY ts;

-- Use OptPFor for maximum compression
CREATE TABLE documents
(
    id UInt64,
    content String,
    INDEX idx_content content TYPE text(
        tokenizer = 'splitByNonAlpha',
        posting_list_codec = 'optpfor'
    )
)
ENGINE = MergeTree
ORDER BY id;

-- Use BinaryPacking for fastest query performance
CREATE TABLE search_index
(
    id UInt64,
    text String,
    INDEX idx_text text TYPE text(
        tokenizer = 'splitByNonAlpha',
        posting_list_codec = 'binarypacking'
    )
)
ENGINE = MergeTree
ORDER BY id;

Implementation Summary

New Files:

  • src/Storages/MergeTree/FastPForBlockCodec.h - CRTP-based wrappers for FastPFor library codecs
  • tests/queries/0_stateless/02346_text_index_posting_list_compression_fastpfor.sql - Test coverage for all FastPFor codecs

Modified Files:

  • src/Storages/MergeTree/IPostingListCodec.h - Added new codec type enums
  • src/Storages/MergeTree/IPostingListCodec.cpp - Codec factory for instantiating new codecs
  • src/Storages/MergeTree/MergeTreeIndexTextPostingListCodec.h - Generic codec template (PostingListCodecGeneric) and codec type aliases
  • src/Storages/MergeTree/MergeTreeIndexTextPostingListCodec.cpp - Template instantiations for all codec types
  • src/Storages/MergeTree/MergeTreeIndexText.cpp - Codec validation in text index creation

Special thanks to Daniel Lemire @lemire and collaborators for the excellent FastPFor library.

@fastio
fastio marked this pull request as draft January 29, 2026 13:02
@nikitamikhaylov nikitamikhaylov added can be tested Allows running workflows for external contributors comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... labels Jan 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5c95b64]

Summary: ❌

job_name test_name status info comment
Build (arm_tidy) failure
Build ClickHouse failure cidb
Docs check dropped
Build (amd_debug) dropped
Build (amd_asan) dropped
Build (amd_tsan) dropped
Build (amd_msan) dropped
Build (amd_ubsan) dropped
Build (amd_binary) dropped
Build (arm_asan) dropped
Build (arm_binary) dropped

@clickhouse-gh clickhouse-gh Bot added pr-feature Pull request with new product feature submodule changed At least one submodule changed in this PR. labels Jan 29, 2026
@fastio fastio changed the title integrate FastPFor as posting list codec Integrate FastPFor as posting list codec Feb 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Dear @fastio, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

@fastio fastio closed this Jun 3, 2026
@CurtizJ

CurtizJ commented Jun 12, 2026

Copy link
Copy Markdown
Member

@fastio

Should we continue? I think adding fastpfor will be interesting. Not sure about other algorithms.

@lemire

lemire commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

If someone is interested, I could help make this forward.

@fastio

fastio commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

@fastio

Should we continue? I think adding fastpfor will be interesting. Not sure about other algorithms.

Sure, I'll add the fastpfor, and reopen this pr now.

@fastio

fastio commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

If someone is interested, I could help make this forward.

That would be great, thank you! I'm interested and happy to help move this forward.

@fastio fastio reopened this Jun 13, 2026
@fastio fastio closed this Jun 13, 2026
@fastio
fastio force-pushed the integration_codec_for_text_index branch from 42f0469 to 16a1aa8 Compare June 13, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... pr-feature Pull request with new product feature submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants