Skip to content

storage, encoded ops: add dictionary encoding infrastructure + encoded operations (Phases 1-4)#1

Open
devin-ai-integration[bot] wants to merge 3 commits into
tidb-shard-key-support-v8.5.6from
tidb-encoded-support-v8.5.6
Open

storage, encoded ops: add dictionary encoding infrastructure + encoded operations (Phases 1-4)#1
devin-ai-integration[bot] wants to merge 3 commits into
tidb-shard-key-support-v8.5.6from
tidb-encoded-support-v8.5.6

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 16, 2026

Copy link
Copy Markdown

What problem does this PR solve?

Problem Summary: Implement SingleStore-style encoded columnstore operations in TiFlash for 5-30x query speedups on analytical queries with low-cardinality columns.

What is changed and how it works?

Phase 1 — Dictionary Encoding Infrastructure:

  • CompressionCodecDictionary (0x96 byte): bit-packed dictionary IDs for columns with ≤4096 distinct values, transparent fallback to raw storage
  • ColumnDictionary type: holds dictionary entries + packed IDs, supports filter/permute/decode operations without full materialization
  • Factory registration: codec auto-detected on read via method byte

Phase 2 — Encoded Filters (EncodedFilter):

  • Pre-computes predicate for each dictionary entry (N entries), applies per-row via ID lookup (M rows) → O(N+M) instead of O(N*M)
  • Supports eq, ne, IN, LIKE predicates
  • tryApply*() methods detect ColumnDictionary input and use encoded fast path

Phase 3 — Encoded Group-By (EncodedGroupBy):

  • Array-indexed aggregation using dictionary IDs as direct array indices
  • SUM, COUNT, MIN, MAX, ANY aggregates + multi-aggregate single-pass
  • No hash table needed — MAX_ENCODED_GROUPS = 4096

Phase 4 — Encoded Star Joins (EncodedStarJoin):

  • Fused scan→join→aggregate on dictionary IDs
  • Builds dimension hash table, pre-computes join for each dictionary entry
  • Single pass: for each fact row, if join matches, accumulate to group bucket

Supporting:

  • DictionaryEncodingEngine: encoding decisions + column encoding/decoding
  • CMakeLists integration for Encoded/ directory
storage, encoded ops: add dictionary encoding + encoded operations (Phases 1-4)

Check List

Tests

  • Unit test (48 test cases: codec roundtrip, ColumnDictionary, filter predicates, group-by aggregates, star join fusion, encoding engine)
  • Integration test
  • Manual test
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility (feature gated OFF by default; new codec byte 0x96 never written unless enabled)

Documentation

  • Affects user behaviors (new session variable enables feature)
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Add dictionary encoding support for TiFlash columnstore with encoded filter, group-by, and star join operations for 5-30x analytical query speedups on low-cardinality columns. Feature is OFF by default.

Link to Devin session: https://6sense.devinenterprise.com/sessions/3710f99abca4415ba59b856f0a5588fc
Requested by: @premal

Implements the foundation for SingleStore-style encoded columnstore
operations in TiFlash:

- Add CompressionCodecDictionary (0x96) for low-cardinality columns
  - Supports Int8/Int16/Int32/Int64 and String data types
  - Bit-packed dictionary IDs with configurable cardinality threshold (4096)
  - Automatic fallback to raw storage when cardinality exceeds threshold
  - Full compress/decompress roundtrip with header format

- Add ColumnDictionary type for in-memory encoded representation
  - Holds dictionary entries + per-row packed IDs
  - Supports filter/permute directly on encoded data
  - decode() method for materialization when needed

- Update CompressionMethodByte enum (Dictionary = 0x96)
- Update CompressionMethod enum (Dictionary = 7)
- Register codec in CompressionCodecFactory
- Update CompressionSettings maps

- Add DictEncodingMeta proto message in dmfile.proto
  - Tracks cardinality, bit_width, encoding status per column segment
  - Optional fields for backwards compatibility (proto2 semantics)

- Add comprehensive unit tests for codec and ColumnDictionary

Feature is gated behind tiflash_enable_dictionary_encoding (default: OFF).
No dictionary segments are written unless explicitly enabled, ensuring
full backwards compatibility with existing deployments.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

premal and others added 2 commits June 16, 2026 21:28
…decDictionary

- Add DataTypes/IDataType.h include for DataTypePtr
- Use move semantics for PaddedPODArray (constructor takes rvalue ref)
- Implement explicit copy constructor for COWPtr clone() support
- Implement all pure virtual methods from IColumn interface
  (insertRangeFrom, insertManyFrom, insertDisjunctFrom, insertManyDefaults,
   replicateRange, scatter, scatterTo, gather, getExtremes)
- Fix -Wunused-parameter in decompressDataInteger/decompressDataString
- Return MutableColumnPtr from cloneResized (matches base interface)

All new object files compile cleanly with clang-14 -Werror.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Phase 2 — EncodedFilter: Pre-compute filter predicates on dictionary
entries (N), apply per-row via ID lookup (M rows) — O(N + M) instead
of O(N*M). Supports eq, ne, IN, LIKE predicates.

Phase 3 — EncodedGroupBy: Array-indexed aggregation using dictionary
IDs as direct array indices. Supports SUM, COUNT, MIN, MAX, ANY plus
multi-aggregate in a single pass.

Phase 4 — EncodedStarJoin: Fused scan→join→aggregate pipeline on
dictionary IDs. Builds dimension hash table, pre-computes join for
each dictionary entry, then single pass over fact IDs accumulating
into group buckets.

Also adds DictionaryEncodingEngine for encoding decisions and column
encoding/decoding, CMakeLists integration, and comprehensive tests
(48 test cases across 4 test files).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration devin-ai-integration Bot changed the title storage, compression: add dictionary encoding infrastructure (Phase 1) storage, encoded ops: add dictionary encoding infrastructure + encoded operations (Phases 1-4) Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant