fix(encoding): Scope preserveStringDictionaryEncoding to string types in RLEEncoding (#973)#973
Open
kewang1024 wants to merge 1 commit into
Open
fix(encoding): Scope preserveStringDictionaryEncoding to string types in RLEEncoding (#973)#973kewang1024 wants to merge 1 commit into
kewang1024 wants to merge 1 commit into
Conversation
|
@kewang1024 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D112307835. |
kewang1024
pushed a commit
to kewang1024/nimble
that referenced
this pull request
Jul 17, 2026
…isitor, and bulkScan (facebookincubator#973) Summary: CONTEXT: When `readWithDictionary` calls `ensureLoaded(preserveDictionaryEncoding=true)` on a non-dict-convertible string column (e.g., TrivialEncoding), inner RLEEncoding enters dict mode (`dictValues_` set, `values_` nullptr). The flat path then calls `materialize()`, `readWithVisitor()`, or `bulkScan()`, all of which called `advanceRunValue()` without checking which mode the RLE is in. `advanceRunValue()` dereferences `values_` (nullptr in dict mode), causing SIGSEGV or producing garbage values. How this happens — `readWithDictionary` entry for non-dict columns: 1. Session properties enabled → enters `readWithDictionary` 2. `ensureLoaded(preserveDictionaryEncoding=true)` loads the chunk. The flag propagates to all encodings in the tree, but only RLEEncoding checks it: if inner values encoding is dictionary-enabled, RLE stores as `dictValues_` (dict mode) instead of `values_` (flat mode). 3. `dictionaryConvertible()` returns false (e.g., TrivialEncoding) → returns false → flat path 4. Flat path reads from the encoding loaded with `true`. Inner RLEs are in dict mode. Two crash variants observed: - SIGSEGV in `RLEEncoding::materialize()`: `advanceRunValue()` dereferences nullptr `values_` directly. - SIGSEGV in `TrivialEncoding::readWithVisitor()` at `StringView` construction: `materialize()` fills the lengths buffer with stale `currentValue_` (never updated in dict mode) → garbage lengths → `pos_` drifts to invalid address. RLEEncoding has two value-storage modes, determined at construction: - Flat mode (`values_` set): `advanceRunValue()` resolves via `values_->nextValue()`. - Dict mode (`dictValues_` set): `advanceRunIndex()` gets the dictionary index, then `alphabet_[currentIndex_]` resolves the actual value. The mode is detectable at runtime by checking `dictValues_ != nullptr`. Only `skip()` already handled both modes. `materialize()`, `readWithVisitor()`, and `bulkScan()` all assumed flat mode. WHAT: Add a dict-aware `advanceRun()` override in `RLEEncoding` that checks `dictValues_ != nullptr` to dispatch to the correct advance method, and resolves `currentValue_` from the dictionary in dict mode. All three affected methods now call this single `advanceRun()` instead of inline `advanceRunValue()` calls. In flat mode (the common case), `advanceRun()` takes the else branch and calls `advanceRunValue()` — identical behavior to before. Differential Revision: D112307835
kewang1024
force-pushed
the
export-D112307835
branch
from
July 17, 2026 00:24
11c4dcf to
85fad33
Compare
kewang1024
force-pushed
the
export-D112307835
branch
from
July 18, 2026 00:33
85fad33 to
eb9dc5f
Compare
kewang1024
pushed a commit
to kewang1024/nimble
that referenced
this pull request
Jul 18, 2026
… in RLEEncoding (facebookincubator#973) Summary: `preserveDictionaryEncoding` propagates to all RLEs in the encoding tree, putting non-string RLEs (e.g., uint32_t length streams) in dict mode. The flat path then crashes — `values_` is nullptr. Add `isStringType` check so only string RLEs enter dict mode. Differential Revision: D112307835
kewang1024
pushed a commit
to kewang1024/nimble
that referenced
this pull request
Jul 18, 2026
… in RLEEncoding (facebookincubator#973) Summary: `preserveDictionaryEncoding` propagates to all RLEs in the encoding tree, putting non-string RLEs (e.g., uint32_t length streams) in dict mode. The flat path then crashes — `values_` is nullptr. Add `isStringType` check so only string RLEs enter dict mode. Differential Revision: D112307835
kewang1024
force-pushed
the
export-D112307835
branch
from
July 18, 2026 10:26
eb9dc5f to
31074cf
Compare
… in RLEEncoding (facebookincubator#973) Summary: `preserveDictionaryEncoding` propagates to all RLEs in the encoding tree, putting non-string RLEs (e.g., uint32_t length streams) in dict mode. The flat path then crashes — `values_` is nullptr. Add `isStringType` check so only string RLEs enter dict mode. Differential Revision: D112307835
kewang1024
force-pushed
the
export-D112307835
branch
from
July 18, 2026 18:32
31074cf to
aa0bc41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
preserveDictionaryEncodingpropagates to all RLEs in the encoding tree, putting non-string RLEs (e.g., uint32_t length streams) in dict mode. The flat path then crashes —values_is nullptr.Add
isStringTypecheck so only string RLEs enter dict mode.Differential Revision: D112307835