Repository navigation
Fix logical error reading a text-indexed column after a lazy or unfinished ALTER - #116549
Conversation
When a MergeTree part still needs a read-time alter conversion for a column (a lazy JSON type hint, or any not-yet-materialized `ALTER MODIFY COLUMN` whose mutation is absent - killed, dropped, or metadata-only), reading that column through the text index code paths (exact-equals direct read with the `array` tokenizer, or the LIKE fallback) did not apply the conversion. The on-disk column (e.g. a JSON path still stored as `Dynamic`) reached `materialize` in `evaluateMissingDefaults` advertising the post-`MODIFY` type and threw `Unexpected return type from materialize` (or crashed / requested a huge allocation, depending on the target type). `MergeTreeReadersChain::executeActionsBeforePrewhere` skipped `performRequiredConversions` entirely when `perform_alter_conversions` was false and `columns_overwritten_by_chain` was empty. That set is populated only from chained `UPDATE`/`DELETE`, so a metadata-only / lazy `MODIFY` (no `UPDATE`/`DELETE`) leaves it empty while the on-fly alter step sets `perform_alter_conversions = false`. Always run `performRequiredConversions` in that branch, skipping only the overwritten-and-not-consumed columns; an empty skip set now converts every read column. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [4f8df11] Summary: ❌
AI ReviewSummaryThis PR makes Findings
Final VerdictNeeds changes: the code fix looks sound, but the regression coverage should make the partially-materialized text-index state deterministic before merge. LLVM Coverage Report |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
The stateless harness randomizes `query_plan_direct_read_from_text_index`; when it injects `0`, the `=` / `LIKE` queries fall back to a regular scan (which converts correctly) and return the right count without exercising the text-index read path the fix is about. Pin it to `1` on the direct-read assertions so the test always covers the fixed path. Co-Authored-By: Claude Opus 4.8 <[email protected]>
| ALTER TABLE t_text_lazy_alter MODIFY COLUMN doc JSON(`a.id` Nullable(String)); | ||
|
|
||
| -- Text index with the `array` tokenizer -> exact-equals direct read (drops the residual equals). | ||
| ALTER TABLE t_text_lazy_alter ADD INDEX idx doc.a.id TYPE text(tokenizer = array) GRANULARITY 100000000; |
There was a problem hiding this comment.
This lazy-JSON case only hits the bug while the old part is still partially materialized for idx: doc.a.id must be read from the physical column so evaluateMissingDefaults sees the stale Dynamic storage under the post-MODIFY type. Nothing here prevents the ADD INDEX mutation on that 4k-row part from finishing before these SELECTs run, and once it does the query can stay green without ever exercising the fixed path.
The nearby partially-materialized text-index tests freeze this state with SYSTEM STOP MERGES immediately after ADD INDEX and/or assert that at least one active part still has secondary_indices_marks_bytes = 0. Please do the same here (or kill the index-materialization mutation) before the direct-read / LIKE assertions so the regression stays deterministic.
Backport #116549 to 26.6: Fix logical error reading a text-indexed column after a lazy or unfinished ALTER
Backport #116549 to 26.8: Fix logical error reading a text-indexed column after a lazy or unfinished ALTER
…lumn after a lazy or unfinished ALTER
Backport #116549 to 26.7: Fix logical error reading a text-indexed column after a lazy or unfinished ALTER
…indexed column after a lazy or unfinished ALTER
…indexed column after a lazy or unfinished ALTER
Cherry pick #116549 to 26.3: Fix logical error reading a text-indexed column after a lazy or unfinished ALTER
…lumn after a lazy or unfinished ALTER
Related: #112213
Reading a column that has a
text(full-text) index through the index — the exact-equals direct read (with thearraytokenizer) or the LIKE fallback — threw theUnexpected return type from materializelogical error when the part still needed a read-time type conversion that no mutation had materialized yet. This happens after a metadata-only or not-yet-finishedALTER MODIFY COLUMNwhose mutation is absent — killed, dropped, or never created (lazy JSON type hints viaallow_experimental_json_lazy_type_hints).MergeTreeReadersChain::executeActionsBeforePrewhereskippedperformRequiredConversionswhenperform_alter_conversionswas false andcolumns_overwritten_by_chainwas empty. That set is populated only from chainedUPDATE/DELETE, so a metadata-only / lazyMODIFY(noUPDATE/DELETE) left the on-disk column (e.g. a JSON path still stored asDynamic) unconverted under its post-MODIFYtype. The fix always runsperformRequiredConversionsin that branch, skipping only the overwritten-and-not-consumed columns.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the
Unexpected return type from materializelogical error when reading a column that has atextindex through the index after a metadata-only or not-yet-materializedALTER MODIFY COLUMN(including lazy JSON type hints) that requires a read-time type conversion.Workflow [PR]
Sync PR [sync-upstream/pr/116549]
Version info
26.8.3.27,26.7.7.18,26.6.5.43