Skip to content

Fix direct read from multiple partially materialized text indexes - #108607

Merged
CurtizJ merged 1 commit into
ClickHouse:masterfrom
CurtizJ:fix-multi-text-index-partial-materialization
Jun 26, 2026
Merged

CurtizJ merged 1 commit into
ClickHouse:masterfrom
CurtizJ:fix-multi-text-index-partial-materialization

Conversation

@CurtizJ

@CurtizJ CurtizJ commented Jun 26, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed direct read from multiple partially materialized text indexes.

Fixes #108530.

Version info

  • Merged into: 26.7.1.123 (included in 26.7 and later)
  • Backported to: 26.6.2.4, 26.5.5.4, 26.4.5.82, 26.3.17.5

When a query uses two or more text indexes that are each only partially
materialized (added via `ALTER ... ADD INDEX` after data was inserted, so
older parts lack the index files), direct read from the text index could
throw `Code 107 FILE_DOESNT_EXIST`, e.g. "File for text index stream
skp_idx_usert_text_idx.idx does not exist".

Each text index gets its own PREWHERE read step holding only its virtual
column. For a part where the index is not materialized and the predicate
uses Hint mode (e.g. `equals` on a `sparseGrams` index), the virtual
column's default expression is the literal `1`, so `injectRequiredColumns`
appends the part's minimum-size physical column purely as a row-count
anchor. The presence of that physical column is also what made
`getIndexReadTaskForReadStep` route the step to the main reader instead of
to the text index reader. However, the anchor is the same column for every
step, and `getReadTaskColumns` deduplicates columns already read by earlier
steps, so only the first index step kept it. The remaining index steps
degenerated into pure virtual-column steps and were routed to
`MergeTreeReaderTextIndex`, which threw because the index file is absent in
that part.

Decide the routing based on actual per-part materialization instead: in
`getIndexReadTaskForReadStep`, route a step to the text index reader only
when `getDeserializedFormat` reports the index is present in the part,
otherwise fall back to the main reader (which fills the virtual column from
its default expression). The behavior is unchanged for materialized parts.

Closes: ClickHouse#108530

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0cc9bd3]

Summary: ✅


AI Review

Summary
  • This PR fixes direct reads from multiple partially materialized text indexes by routing each per-part text-index read step to MergeTreeReaderTextIndex only when the relevant index files are present, otherwise falling back to the main reader so the text-index virtual column is produced from its default expression. I did not find any correctness or safety issue that warrants an inline review comment.
Missing context / blind spots
  • ⚠️ I could not run the new stateless test locally because this checkout has no local build* directory or clickhouse binary. The public S3 PR report for commit 0cc9bd36f6ac6211a1065bdbbbfb8593c781d6c9 currently returned zero test-result rows; a normal CI/stateless run would close this gap.
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 26, 2026
@CurtizJ CurtizJ added pr-must-backport Pull request should be backported intentionally. Use this label with great care! v26.2-must-backport v26.4-must-backport v26.6-must-backport labels Jun 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.50% 77.50% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 15/15 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@CurtizJ CurtizJ self-assigned this Jun 26, 2026
@CurtizJ
CurtizJ added this pull request to the merge queue Jun 26, 2026
Merged via the queue into ClickHouse:master with commit 9798499 Jun 26, 2026
167 checks passed
@CurtizJ
CurtizJ deleted the fix-multi-text-index-partial-materialization branch June 26, 2026 22:13
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 26, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Jun 26, 2026
Cherry pick #108607 to 26.3: Fix direct read from multiple partially materialized text indexes
robot-clickhouse added a commit that referenced this pull request Jun 26, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Jun 26, 2026
Cherry pick #108607 to 26.4: Fix direct read from multiple partially materialized text indexes
robot-clickhouse added a commit that referenced this pull request Jun 26, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Jun 26, 2026
Cherry pick #108607 to 26.5: Fix direct read from multiple partially materialized text indexes
robot-clickhouse added a commit that referenced this pull request Jun 26, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Jun 26, 2026
Cherry pick #108607 to 26.6: Fix direct read from multiple partially materialized text indexes
robot-clickhouse added a commit that referenced this pull request Jun 26, 2026
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 26, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jun 27, 2026
Backport #108607 to 26.6: Fix direct read from multiple partially materialized text indexes
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 28, 2026
CurtizJ added a commit that referenced this pull request Jun 29, 2026
The cherry-pick of #108607 calls `IMergeTreeIndex::getDeserializedFormat`
with a third `const IDataPartStorage *` argument, which exists only on
master (for packed index substreams via the `skp_idx.packed` overlay).
On this release branch the method takes two arguments, so the build failed
with "too many arguments to function call".

On master, passing `storage == nullptr` disables the archive check, making
the call equivalent to the two-argument form used everywhere else on this
branch, so dropping the argument is behavior-preserving here.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
CurtizJ added a commit that referenced this pull request Jun 29, 2026
The cherry-pick of #108607 calls `IMergeTreeIndex::getDeserializedFormat`
with a third `const IDataPartStorage *` argument, which exists only on
master (for packed index substreams via the `skp_idx.packed` overlay).
On this release branch the method takes two arguments, so the build failed
with "too many arguments to function call".

On master, passing `storage == nullptr` disables the archive check, making
the call equivalent to the two-argument form used everywhere else on this
branch, so dropping the argument is behavior-preserving here.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
CurtizJ added a commit that referenced this pull request Jun 29, 2026
The cherry-pick of #108607 calls `IMergeTreeIndex::getDeserializedFormat`
with a third `const IDataPartStorage *` argument, which exists only on
master (for packed index substreams via the `skp_idx.packed` overlay).
On this release branch the method takes two arguments, so the build failed
with "too many arguments to function call".

On master, passing `storage == nullptr` disables the archive check, making
the call equivalent to the two-argument form used everywhere else on this
branch, so dropping the argument is behavior-preserving here.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
CurtizJ added a commit that referenced this pull request Jun 29, 2026
Backport #108607 to 26.5: Fix direct read from multiple partially materialized text indexes
CurtizJ added a commit that referenced this pull request Jun 29, 2026
Backport #108607 to 26.4: Fix direct read from multiple partially materialized text indexes
CurtizJ added a commit that referenced this pull request Jun 29, 2026
Backport #108607 to 26.3: Fix direct read from multiple partially materialized text indexes
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…x-partial-materialization

Fix direct read from multiple partially materialized text indexes
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
STOR: direct read from several partially materialized text indexes -> wrong/exc.
Effect in the production build a394e92: its upstream test(s) 04411_text_index_multiple_partially_materialized fail on it and pass on official 26.8.8.8, run on isolated servers (evidence/fix_ci_20260925/upstream_repro/server_triage_PROD263_vs_UP2688.tsv).
Upstream patch unchanged, with its test(s): 04411_text_index_multiple_partially_materialized.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
…ustom settings prefixes, reviewed dispatch sites, two open defects)

The CAND4 (e7432ca) release gate reported, besides the open KD-D512-MIXED-GROUPBY-NULLABLE:
- 3 skipped tests (04303, 04305, 04357: "no shard"): run_checks.sh passed --no-shard, a leftover from before the
  isolated server listened on 127.0.0.1-3 with the test clusters. Dropped, so clickhouse-test detects shard support
  from the server config as the triage runs do.
- 05023 (ClickHouse#115334's test): the isolated server allowed only the custom_ settings prefix; it now allows SQL_,custom_
  like the upstream test config (tests/config/config.d/custom_settings_prefixes.xml). isolated_ch.sh is vendored from
  the skill draft; VENDORED.sha256 updated.
- 2 dispatch-scan candidates: the Int512 fast path of 7581066 (bothFitInt256/mulInt256Range); reviewed, not a gap.
- 04411 (ClickHouse#108607's test): its three-index section recurses in equals() on every 26.3 build, including production and
  builds without the backport (FILE_DOESNT_EXIST, the bug ClickHouse#108607 fixes, is gone). New open KD-UP-TEXTINDEX-DIRECTREAD-3IDX
  (pre-existing upstream 26.3 bug, upstream fix not identified; workaround query_plan_direct_read_from_text_index = 0).
- 04881 (ClickHouse#114624's test): its only differing line is the reference with the host name 'build' replaced by 'localhost'
  by clickhouse-test; the output is otherwise identical. New open KD-ENV-HOSTNAME-SUBSTITUTION (environment); the test
  and its reference are not edited.
The fifth failure, 04409, is the missing dependency ClickHouse#106905 (previous commit). Registry: 147 entries, 3 open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
…ion comes with the ClickHouse#108607 backport)

Correction of 4d9f96f, whose message and registry entry said that the three-index section of 04411 recursed on
every 26.3 build, including production and builds without the backport. That came from reproduction runs capped at
TasksMax=512: ClickHouse could not start its threads there and dumped core. Rerun with TasksMax=8192:
- production a394e92, hotfix cd0d608, CAND3 7581066: FILE_DOESNT_EXIST (107), the bug ClickHouse#108607 fixes;
- CAND4 e7432ca: TOO_DEEP_RECURSION (306), only for the query that uses all three indexes; one- and two-index
  queries (and a cross-column check) are correct; official 26.8.8.8 is correct.
The entry stays open with the corrected root cause; the backport is kept (it fixes the one- and two-index cases).
Evidence: evidence/fix_ci_20260925/textindex_recursion_26_3/results.txt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
 text index prewhere fix)

STOR: with query_plan_direct_read_from_text_index and use_skip_indexes_on_data_read, each text index read is a
None-type PREWHERE step. IndexReadTasks/IndexReadColumns were std::unordered_map: the map is copied into the read
pool and iterated again in getPrewhereActions and getReadTaskColumns, and a copy need not iterate in the same order,
so the PREWHERE readers and the PREWHERE actions of the index steps could be paired differently. In addition
MergeTreeRangeReader executed the actions of None-type steps on its sample block although
executePrewhereActionsAndFilterColumns skips them at run time, so the sample block and the data diverged.
Upstream switches both maps to std::map and skips None-type steps on the sample block (26.3 backport ClickHouse#107758 of
1c1c031 from ClickHouse#98882; 26.4+ have it through ClickHouse#98882).
Effect in the fork: with three partially materialized text indexes in one query (04411, third section) the backport
of ClickHouse#108607 (a6ab685) ran equals(a, 'alpha') on a column that was not the String column a and failed with
TOO_DEEP_RECURSION (KD-UP-TEXTINDEX-DIRECTREAD-3IDX); with a row policy on a String column the upstream test 04332
fails with ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER. Upstream patch unchanged (applies cleanly), with its test
04332_text_index_direct_read_row_policy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.2-must-backport v26.4-must-backport v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Direct read from text index fails with partially materialized indexes

4 participants