Skip to content

Cherry pick #129339 to 26.10: Let automatic parallel replicas handle direct read from a text index - #131627

Merged
nickitat merged 6 commits into
backport/26.10/129339from
cherrypick/26.10/129339
Nov 14, 2026
Merged

nickitat merged 6 commits into
backport/26.10/129339from
cherrypick/26.10/129339

Conversation

@robot-ch-test-poll4

Copy link
Copy Markdown
Contributor

Original pull-request #129339

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

nickitat and others added 5 commits November 4, 2026 16:01
… a text index

The plan for automatic parallel replicas is optimized with
`query_plan_optimize_primary_key` off, so `optimizePrimaryKeyConditionAndLimit`
never builds the indexes of its reads. Direct read from a text index takes
the conditions it rewrites from those indexes, so the single-node plan got
`__text_index_*` virtual columns while the replicas plan kept `hasToken`.
The steps hashed differently, every such query ended in
`AutoParallelReplicasPlansNotComparable`, and parallel replicas were never
enabled for it.

Build the index conditions for a read of a table with a text index even when
the pass is off. Index analysis is lazy, so this builds conditions only, and
`adoptFiltersFrom` replaces them with the single-node read's if the replicas
plan is chosen.

On a 20M-row table with query-based parallel replicas, a `hasToken` query
with `GROUP BY` now gets `AutoParallelReplicasApplied` and runs on 3
replicas instead of `PlansNotComparable`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ing them

The previous commit ran `optimizePrimaryKeyConditionAndLimit` on reads of the
probe plan of automatic parallel replicas. That is not condition-only: building
`KeyCondition` executes the subquery of every `IN` whose set the probe plan
could not adopt from the single-node plan, such as the UUID-keyed set of
`query_plan_convert_join_to_in`. The subquery ran a second time even when the
candidate was rejected, so a query near `max_rows_to_read` could throw
`TOO_MANY_ROWS`. Adopting the single-node read's `indexes` into the probe read
is no better: `updatePrewhereInfo` takes their presence as the sign that
`applyFilters` ran and builds the PREWHERE sets.

Leave the probe reads untouched. The builder of the probe plan gets a lookup of
the single-node read each probe read stands for, paired by table expression
name as `transplantAnalysisToAllReads` pairs them, and only
`collectTextIndexReadInfos` uses it, for a read with no index conditions of its
own. Both plans then rewrite the same text-search functions, and nothing is
built that the single-node plan has not already built.

The test now also checks that a JOIN converted to `IN` next to a `hasToken`
predicate builds its set once and reads as many rows as without parallel
replicas; with the previous commit it built the set twice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…allel replicas

Now that the plan for automatic parallel replicas rewrites its reads for direct read from a text index,
`optimizeTrivialCountFromTextIndex` matched those reads. They have no index analysis, so the pass ran it
over the rewritten filter, where the text index is of no use, and `force_data_skipping_indices` threw
`INDEX_NOT_USED`. When the single-node plan answers the count from the text index, automatic parallel
replicas does not consider the query, so the pass has nothing to do there.

Failures: `02346_text_index_bug110350`, `04654_text_index_merge_with_empty_part` with
`automatic_parallel_replicas_mode = 2`.
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129339&sha=latest&name_0=PR
#129339

05507 also runs the query in mode 1 after collecting statistics and checks that the plan with parallel
replicas is applied, is used, and returns the single-node result.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…irect-read

# Conflicts:
#	src/Processors/QueryPlan/Optimizations/considerEnablingParallelReplicas.cpp
Let automatic parallel replicas handle direct read from a text index
@robot-ch-test-poll4 robot-ch-test-poll4 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Nov 14, 2026
@nickitat

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

…thub.com/ClickHouse/ClickHouse into cherrypick/26.10/129339

# Conflicts:
#	src/Interpreters/InterpreterSelectQueryAnalyzer.cpp
#	src/Processors/QueryPlan/Optimizations/considerEnablingParallelReplicas.cpp

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

🕵 Resolved and pushed in merge commit aade18487; the PR now reports a clean merge state.

Copilot AI requested a review from nickitat November 14, 2026 14:40
@nickitat
nickitat merged commit e6678c4 into backport/26.10/129339 Nov 14, 2026
2 checks passed
@nickitat
nickitat deleted the cherrypick/26.10/129339 branch November 14, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants