Repository navigation
Let automatic parallel replicas handle direct read from a text index - #129339
Conversation
… 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]>
|
Workflow [PR], commit [2cefcde] Summary: ✅
AI ReviewSummaryThis PR enables automatic parallel replicas for query-based plans that read directly from a text index. The probe borrows the corresponding single-node read's index conditions without rebuilding its sets, and skips the incompatible trivial-count optimization. No actionable findings remain. The previous coverage finding is addressed by mode-1 execution assertions, and Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes80 object files changed (+39.32 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units160 translation units recompiled, 1567 s compile time in total, 160 of them have a recent master baseline. |
…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]>
groeneai
left a comment
There was a problem hiding this comment.
Looks good to me. I built 222b0acd (debug) and compared it with master 21809eaa on a three-replica localhost cluster (parallel_replicas_plan_based = 0, parallel_replicas_local_plan = 1, cost-model settings as in 05507).
05507matches the reference. On master it fails at the last two checks (not_comparable = 1with no statistics collected, thenapplied = 0). Its05507_appliedquery in mode 1 also covers what the open bot thread on the test asks for.- 34 query shapes over the text index, each run without parallel replicas, then in mode 2, then in mode 1, give the same result and no exception:
hasToken,hasAnyTokens,hasAllTokens,LIKE,ILIKEwithuse_text_index_like_evaluation_by_dictionary_scan,NOT, anORwith a non-index condition, explicitPREWHERE, alower()preprocessor, a partially materialized index, a second text index onmapKeys(m)plus aminmaxindex on the same table,INover the same table and over another one, a self-join,force_data_skipping_indices = 'idx_str', and each ofquery_plan_direct_read_from_text_index,use_skip_indexes_on_data_read,optimize_move_to_prewhere,use_query_condition_cacheset to 0. 27 are adopted in mode 1 (AutoParallelReplicasAppliedandParallelReplicasUsedCountboth 1), 1 (count()overILIKE) is matched and then rejected by the cost model, and 4 (count()answered from the index,UNION ALL) are skipped before the probe plan is built. - The other 2 still end in
PlansNotComparable:GROUP BY ... ORDER BY ... LIMIT 3, and thequery_plan_convert_join_to_injoin from the test. Both do the same with a plain filter (WHERE id % 1000 = 7) instead of the text index, so neither comes from this PR. - The finder's raw pointers to the single-node reads do not outlive the builder call: the finder lives only in the builder's local
QueryPlanOptimizationSettings, and what the probe'sIndexReadTaskkeeps is a value copy ofMergeTreeIndexWithCondition.
…irect-read # Conflicts: # src/Processors/QueryPlan/Optimizations/considerEnablingParallelReplicas.cpp
Cherry pick #129339 to 26.10: Let automatic parallel replicas handle direct read from a text index
…ect read from a text index
Backport #129339 to 26.10: Let automatic parallel replicas handle direct read from a text index
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Automatic parallel replicas can now enable parallel replicas for queries that use direct read from a text index.
Automatic parallel replicas never enabled parallel replicas for a query that reads directly from a text index (
query_plan_direct_read_from_text_index, on by default). Every such query ended inAutoParallelReplicasPlansNotComparable.The probe plan with parallel replicas is optimized with
query_plan_optimize_primary_keyoff, so its reads have no index conditions. Direct read takes the conditions it rewrites from them, so the single-node plan got the__text_index_*virtual column while the probe plan kepthasToken, and the two plans hashed differently.The builder of the probe plan now gets a lookup of the single-node read each probe read stands for, paired by table expression name as
transplantAnalysisToAllReadspairs them.collectTextIndexReadInfosuses it for a read with no index conditions of its own. The probe reads themselves are left untouched: building their index conditions would executeINsubqueries the probe plan cannot adopt (e.g. the UUID-keyed set ofquery_plan_convert_join_to_in), and adopting the single-node read'sindexeswould makeupdatePrewhereInfobuild the PREWHERE sets.On a 20M-row table with query-based parallel replicas, a
hasTokenquery withGROUP BYgoes fromPlansNotComparabletoAutoParallelReplicasAppliedon 3 replicas. The plan-based implementation is still blocked by #118265 and by the guard for #116360.Workflow [PR]
Sync PR [sync-upstream/pr/129339]
Version info
26.11.1.2307-master(included in26.11and later)26.10.5.15