Skip to content

Do not distribute a read that uses direct read from a text index - #116363

Merged
devcrafter merged 5 commits into
masterfrom
keep-text-index-direct-read-local-for-parallel-replicas
Sep 5, 2026
Merged

devcrafter merged 5 commits into
masterfrom
keep-text-index-direct-read-local-for-parallel-replicas

Conversation

@devcrafter

@devcrafter devcrafter commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

query_plan_direct_read_from_text_index (default true) rewrites the text-search functions in a read's PREWHERE into synthetic __text_index_<index>_<function>_<hash> virtual columns, which only that read's index read tasks materialize. The task map is not part of ReadFromMergeTree::serialize, so shipping such a read as a plan fragment fails on the replica in two ways:

Nothing rejected such a read on this path: ReadFromMergeTree::isSerializable is true unconditionally, and the only existing refusal - supportsBucketedRead / verifyBucketedReadSupported - applies to a bucketed distributed read (make_distributed_plan), not to an ordinary shipped fragment. This keeps such a read local in mergeTreeReadCanBeShipped, right next to the Top-K guard, which exists for exactly the same reason - a synthetic column the replica cannot resolve.

Verified locally against a debug server with parallel_replicas_plan_based = 1:

Because the read is no longer distributed, 02346_text_index_parallel_replicas would report ParallelReplicasUsedCount = 0, so it pins parallel_replicas_plan_based = 0 to keep asserting what it was written for. Serializing the index read tasks so these reads can be distributed again - and dropping both the guard and that pin - is tracked in #116360.

Closes: #113664
Related: #116360
Related: #112351

Changelog category (leave one):

  • Experimental Feature

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

Fixed Column '__text_index_...' not found in table and Query builder not found for text search query when a query using a text index read with parallel_replicas_plan_based enabled.


Workflow [PR]
Sync PR [sync-upstream/pr/116363]

Version info

  • Merged into: 26.9.1.761 (included in 26.9 and later)

`query_plan_direct_read_from_text_index` rewrites the text-search functions in a read's `PREWHERE`
into `__text_index_*` virtual columns, which only that read's index read tasks materialize. The task
map is not serialized, so shipping such a read as a plan fragment fails on the replica:

- `Code: 10. DB::Exception: Column '__text_index_idx_str_like_<hash>' not found in table` while the
  replica deserializes the read step, and
- `Code: 49. DB::Exception: Query builder not found for text search query` at execution time when
  `PREWHERE` and `WHERE` carry different text-search queries.

`ReadFromMergeTree::isSerializable` already reports the step as unshippable and
`verifyBucketedReadSupported` rejects it for `make_distributed_plan`, but plan-based parallel
replicas plants its split marker without consulting either. Keep such a read local in
`mergeTreeReadCanBeShipped`, next to the Top-K guard, which exists for the same reason - a synthetic
column the replica cannot resolve.

The read is then not distributed at all, so `02346_text_index_parallel_replicas` pins the
query-based implementation to keep asserting what it was written for. Serializing the index read
tasks, so these reads can be distributed again, is left to
#116360.

Closes: #113664

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

clickhouse-gh Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e6a84d8]

Summary: ✅


AI Review

Summary

This PR keeps ReadFromMergeTree steps that carry direct text-index read tasks out of plan-based parallel-replicas fragments by returning false from mergeTreeReadCanBeShipped, which matches the existing local-only guards for other non-serializable read state. That containment fix looks correct, but the PR still removes the only stateless coverage of the affected plan-based path without adding a replacement regression, so I cannot approve it yet.

Tests
  • ⚠️ [tests/queries/0_stateless/02346_text_index_parallel_replicas.sql:18] The PR promises that with parallel_replicas_plan_based = 1 a text-index direct read now stays local instead of being shipped and failing, but the updated test forces parallel_replicas_plan_based = 0 and never exercises that contract. Please add a focused plan-based regression case that keeps query_plan_direct_read_from_text_index = 1 and asserts both correct results and non-distribution of the read (EXPLAIN has no ReadFromParallelReplicas or ProfileEvents['ParallelReplicasUsedCount'] = 0). It should include a PREWHERE/WHERE split shape from #113664, because that is one of the two failure modes called out in the PR body.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: add a plan-based stateless regression that proves the read stays local under parallel_replicas_plan_based = 1, preferably covering the PREWHERE + WHERE split-query shape from #113664.

LLVM Coverage Report

Measured on commit e6a84d8.

Metric Baseline Current Δ
Lines 88.70% 88.70% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 81.10% 81.10% +0.00%

Changed lines: Changed C/C++ lines covered: 4/5 (80.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Aug 25, 2026
Review feedback: `ReadFromMergeTree::isSerializable` returns `true` unconditionally, so the previous
comment was wrong to say it reports a read with index read tasks as unshippable. What actually
happens is that `ReadFromMergeTree::serialize` does not carry the task map, and only
`supportsBucketedRead` refuses such a read - for a bucketed distributed read, not for an ordinary
shipped fragment. Nothing rejected it on this path, which is why the guard is needed here.

Comment only.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
-- read from a text index (its index read tasks are not serialized), so it keeps such a read local and
-- `ParallelReplicasUsedCount` would be 0. Drop this pin once
-- https://github.com/ClickHouse/ClickHouse/issues/116360 is fixed.
SET parallel_replicas_plan_based = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pin removes the only stateless coverage of text-index reads under parallel_replicas_plan_based, which is the exact contract this PR is changing. The guard in applyParallelReplicas.cpp looks reasonable, but without a parallel_replicas_plan_based = 1 case that proves the query now stays local instead of throwing, a future change can re-enable fragment shipping and bring back #113664 with no test failure.

We already have the right pattern in tests like 04647_pr_plan_based_final.sql and 04838_pr_plan_based_top_k_filter.sql: keep plan-based mode on, assert the results still match local execution, and pin the shape (EXPLAIN has no ReadFromParallelReplicas, or ProfileEvents['ParallelReplicasUsedCount'] = 0). Please keep this query-based pin only if you also add that focused plan-based regression case here or in a new test.

@clickhouse-gh

clickhouse-gh Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e6a84d8aa with master 255227391 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 16 s compile time in total, 7 of them have a recent master baseline.

Job report

devcrafter and others added 2 commits August 27, 2026 13:11
…dex guard

The merge that brought in the `hasPinnedBlockNumbers` guard placed it between
`if (!read.getIndexReadTasks().empty())` and its `return false;`, so the text-index guard ended up
guarding the next `if` instead of returning. It only refused to ship a read that had pinned block
numbers as well, which made it a no-op for the case it was added for.

`clang-tidy` caught this as `readability-misleading-indentation` in `Build (arm_tidy)`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). label Sep 4, 2026
@devcrafter devcrafter self-assigned this Sep 4, 2026
@devcrafter
devcrafter enabled auto-merge September 4, 2026 20:54
@devcrafter
devcrafter added this pull request to the merge queue Sep 5, 2026
Merged via the queue into master with commit cdc26e3 Sep 5, 2026
175 checks passed
@devcrafter
devcrafter deleted the keep-text-index-direct-read-local-for-parallel-replicas branch September 5, 2026 03:47
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). pr-experimental Experimental Feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

2 participants