Skip to content

Randomize parallel_replicas_min_number_of_rows_per_replica - #71028

Open
devcrafter wants to merge 49 commits into
masterfrom
pr-randomize-rows-to-read-setting
Open

devcrafter wants to merge 49 commits into
masterfrom
pr-randomize-rows-to-read-setting

Conversation

@devcrafter

@devcrafter devcrafter commented Oct 24, 2024 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Details

The setting enables code execution, which can trigger hidden bugs, in particular in GLOBAL JOINs with parallel replicas. Discovered one while doing #70658 within 02967_parallel_replicas_joins_and_analyzer test


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

@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 24, 2024
@antaljanosbenjamin antaljanosbenjamin self-assigned this Oct 25, 2024
Comment thread tests/clickhouse-test Resolved
@clickhouse-gh

clickhouse-gh Bot commented Dec 31, 2024

Copy link
Copy Markdown
Contributor

Dear @antaljanosbenjamin, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@clickhouse-gh

clickhouse-gh Bot commented Feb 11, 2025

Copy link
Copy Markdown
Contributor

Dear @antaljanosbenjamin, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@alexey-milovidov alexey-milovidov self-assigned this Jul 27, 2025
@clickhouse-gh

clickhouse-gh Bot commented Jul 27, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cd118cf]

Summary: ✅


AI Review

Summary

Reviewed #71028 at cd118cfeb9bf2b08008ce8b16acad6062aaa1cc4, including the complete diff, current planner code, and all prior discussion. The PR randomizes parallel_replicas_min_number_of_rows_per_replica, excludes incompatible transaction tests from parallel-replica runs, pins settings for planner-accounting assertions, and keeps joins logical in the disposable filter-collection plan. No actionable findings remain. The earlier transaction-exclusion and forced-hash issues are addressed; the automatic-parallel-replicas probe now explicitly skips the row estimate behind the original rollout concern.

The disposable plan is consumed by the ReadFromDummy traversal, which still exports filter DAGs and PREWHERE information. Downstream consumers receive those through Planner and SelectQueryInfo: replica-count estimation, StorageDistributed shard pruning, StorageView predicate forwarding, StorageMerge child planning, and cluster-engine task pruning. The logical join representation remains internal to the disposable plan.

Missing context / blind spots
  • ⚠️ Full CI and CH Inc sync for this head are still pending. The current-head Praktika report reports no failures so far, and Fast test passed 05452_pr_min_rows_estimate_direct_join_merge_tree, including its nested-query and inequality-only ASOF JOIN cases. No local build or test run was performed; completed required checks will close this validation gap.
Final Verdict

Status: ✅ Approve. No new inline findings or thread changes. Required CI checks must finish successfully before merge.

@alexey-milovidov

Copy link
Copy Markdown
Member

@devcrafter, it shows errors.

@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

Dear @alexey-milovidov, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@alexey-milovidov alexey-milovidov self-assigned this Oct 17, 2025

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A very good change!

@alexey-milovidov

Copy link
Copy Markdown
Member

@devcrafter, it failed.

@clickhouse-gh

clickhouse-gh Bot commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

Dear @alexey-milovidov, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@alexey-milovidov

Copy link
Copy Markdown
Member

@devcrafter, more changes are needed.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master into the branch again (8756552a877). The only conflict was the tag line of 01169_old_alter_partition_isolation_stress.sh: master added no-msan with an explanation, and I kept both no-msan and this PR's no-parallel-replicas. The diff of this PR is otherwise unchanged.

The merge brings in #121269 (class 1 and class 2: 03560_parallel_replicas_projection, 02155, 04032, 03171) and #124341 (the 04839_parallel_replicas_cancel_before_announcement pin, thanks @groeneai). So the next run should drop those reds. Still open: #121273 (05042_autopr_share_prepared_sets and the other prepared-sets reds), #121256, #121283 and #122339. The option A vs B question for 03800 / 04249 still needs a human decision.

@groeneai, about #121301: I prefer (B). Cut it down to its regression test, because 05250 pins mode 0 and does not cover the automatic-parallel-replicas probe with force_primary_key. If the test passes on current master it is a cheap guard. Close the PR only if the test turns out to duplicate existing coverage.

@groeneai

Copy link
Copy Markdown
Collaborator

Done as (B): #121301 now contains only 05233 (head 0aa5368). The src/ change is dropped, since #121269 carries the same fix.

It does not duplicate existing coverage: no test on master combines automatic_parallel_replicas_mode 1 or 2 with force_primary_key and a throwing row limit (05250 pins mode 0). On master d6c2532ef90 it passes 50 of 50 runs under default randomization and 50 of 50 under the settings from this PR.

I also added a per-arm check of AutomaticParallelReplicasProbePlansBuilt: with the fix in place every expected error is the same whether or not the probe runs, so without it the test could pass by skipping the probe. With parallel_replicas_local_plan = 0 only that check goes red.

…o-read-setting

# Conflicts:
#	tests/queries/0_stateless/05043_distributed_alias_column_window_order.sql
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master again (e6a050daab8). The only conflict was in 05043_distributed_alias_column_window_order.sql: master removed enable_analyzer = 1 from the two parallel-replicas queries. I took master's lines and kept this PR's parallel_replicas_min_number_of_rows_per_replica = 0 pin. The diff of this PR is otherwise unchanged.

05317_sync_merges_waits_for_commit failed in both flaky checks of the previous run, and it failed the same way on 05ea8d329d9. The cause is not this PR's setting. It is a race in InterpreterSystemQuery::syncMerges. The server log shows CancellationChecker: Cancelling the task because of the timeout and then QUERY_WAS_CANCELLED instead of TIMEOUT_EXCEEDED. CancellationChecker starts counting max_execution_time earlier than the loop's own start, so it can fire first, and the loop then threw a plain cancellation. The fix is in a separate PR: #127759. The heavier flaky check of this PR probably widens the race window, since it runs about 430 tests here.

@groeneai, thanks for cutting #121301 down to the 05233 test.

The other reds are the same parallel-replicas bugs as before: 05042_autopr_share_prepared_sets (#121273), 03800_autopr_reuse_index_analysis and 04249_query_condition_cache_fine_grained_granules (the option A vs B decision), and the direct-join and 04052 failures. The review thread about gating the randomization still waits on the fix-then-randomize vs. land-and-track decision.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The CI run on e6a050daab8 has only failures that were already triaged:

The branch is up to date with master, so there is nothing to change in this PR right now. The open review thread is still waiting for the fix-then-randomize vs. land-and-track decision.

alexey-milovidov and others added 4 commits October 26, 2026 04:54
…er dummy tables

`collectFiltersForAnalysis` plans the query once more over dummy tables and optimizes that plan to
collect the pushed-down filters. With `join_algorithm = 'direct'` the optimization tried to build a
direct join with a `MergeTree` right table, whose read is a `ReadFromDummy` there, and threw
`None of the algorithms enabled by the 'join_algorithm' setting [direct] can execute this ALL INNER JOIN`.
The filter collection runs for `MergeTree` tables when `parallel_replicas_min_number_of_rows_per_replica`
is positive, so randomizing that setting made `05211_pr_plan_based_direct_join_merge_tree` fail.

The dummy plan is never executed, so use the `hash` algorithm there. Adjust the contexts of all nested
queries and unions, not only the top-level one, because each of them is planned with its own context.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=71028&sha=e6a050daab862c05e6edc5947da0bc615b48ad12&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29
#71028

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… `04052`

Both tests count the `mergeTreeAnalyzeIndexes` queries issued for a read. A positive
`parallel_replicas_min_number_of_rows_per_replica` makes the planner estimate the rows to read before
the read itself, and that estimate issues more index analysis queries, so the counts do not match.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=71028&sha=e6a050daab862c05e6edc5947da0bc615b48ad12&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29
#71028

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Planner/Planner.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). and removed comp-testing Test content only (no production code). labels Oct 26, 2026
`collectFiltersForAnalysis` forced `join_algorithm = 'hash'` to avoid
`NOT_IMPLEMENTED` for a direct join over dummy tables. That broke valid
queries which `hash` cannot execute, e.g. an inequality-only `ASOF JOIN`
with `full_sorting_merge` over a `View` (the filter-collection plan runs
for `View` even without parallel replicas).

The plan is never executed, so keep joins logical instead
(`keep_logical_steps`): no physical algorithm is chosen, and the filter
push-down still happens before the conversion. Add the `ASOF JOIN` case
to the regression test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit to groeneai/ClickHouse that referenced this pull request Oct 26, 2026
…cker` stops it

`CancellationChecker` measures `max_execution_time` from the registration of the query
in the process list, which is earlier than the `start` of the polling loop in
`InterpreterSystemQuery::syncMerges`. When the checker fires first, the loop saw only
`isQueryCanceled` and threw `QUERY_WAS_CANCELLED`, although the cancel reason is the
timeout. Check `QueryStatus::throwIfKilled` instead, which throws `TIMEOUT_EXCEEDED`
for a timeout cancellation.

This made `05317_sync_merges_waits_for_commit` fail in the flaky check of ClickHouse#71028:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=71028&sha=8756552a877bdecfeaed1cce864ace0a31b8288a&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 5 commits November 2, 2026 15:27
…ad-setting

# Conflicts:
#	tests/queries/0_stateless/01169_alter_partition_isolation_stress.sh
…count planner side effects

A positive value makes the planner build one more plan to estimate the rows to read.
That plan runs the index analysis, the query condition cache, the join order optimizer
and subquery caching once more, which changes exact counters and log lines in:
`03229_query_condition_cache_profile_events`, `03622_explain_indexes_distributed_index_analysis_in`,
`05055_subquery_profile_query_cache`, `05293_dpsub_conflict_detector_flattens_all_join_kinds`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=71028&sha=9839373cf30abf823cbcecfdfac1f8e7773b47b7&name_0=PR

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…f_rows_per_replica`

- `03518_key_condition_binary_search` counts index search profile events. The extra plan
  that estimates the rows to read runs the index analysis again, so pin the setting to `0`.
- `02769_parallel_replicas_unavailable_shards` expects the unavailable replica to be picked.
  A positive value lowers the number of replicas for the 10-row table, so the counter stays `0`.
- `05452_pr_min_rows_estimate_direct_join_merge_tree` flakily failed in the `distributed plan`
  job: a remote replica that receives a serialized query plan cannot build a direct join yet
  (#105260). The test is about the plan built on
  the initiator, so it now sets `serialize_query_plan = 0`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=71028&sha=6494bace60a09a4c9e5697f5a0d03ed06a4e36d9&name_0=PR
PR: #71028

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… `05099`

Both tests count query condition cache effects (`SelectedMarks` and cache hits).
With `parallel_replicas_min_number_of_rows_per_replica 1` the planner builds an extra
plan to estimate the rows to read, and that estimate consults the query condition
cache too, so the counts change. Pin the setting to `0`, as in `03229`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=71028&sha=e2b86d280fadb12304521db43e6bbd0053ffd136&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20sequential%29
PR: #71028

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 6, 2026
…plan

With parallel_replicas_min_number_of_rows_per_replica > 0,
collectFiltersForAnalysis plans a clone of the query in which only the
join-tree tables are replaced by dummies, and it disabled parallel replicas
only in the clone's top context. An IN subquery keeps its real table and
shares its context with the original tree, so that throwaway planner planned
the subquery with parallel replicas: a row estimate (one index analysis of
the subquery's read), a coordinator and a local replica plan, none of which
is ever executed since ClickHouse#121283 made the outer estimate decline on an unbuilt
set. The real execution then analyzes the subquery read again.

Copy the context of every QueryNode/UnionNode of the clone and disable
parallel replicas there, the way the local replica plan, the remote plan and
scalar subqueries already do. Copies are assigned to the clone's nodes only,
so the original query tree keeps its settings.

Related: ClickHouse#71028
Related: ClickHouse#118275

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

Conflict in `collectFiltersForAnalysis`: master now disables parallel replicas in every (sub)query
context via `traverseQueryTree` (also skipping materialized CTEs), which supersedes the PR's own
equivalent loop, so master's version is taken.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (59415bd73b7), no conflicts; the PR diff is unchanged. The only red check on 0b98aa3e0ca was CH Inc sync ("tests failed"), and none of its failures come from this PR:

  • 05565_uniq_exact_variadic_chunked_keys (FIPS build): MD5 is not available in FIPS mode. Already fixed on master by Use sipHash128 instead of MD5 in test 05565_uniq_exact_variadic_chunked_keys #130141, which this merge pulls in.
  • 04652_adaptive_aggregator_exact_results (ASan, distributed cache): infrastructure error DISTRIBUTED_CACHE_SERVER_SLOW_DOWN from the distributed cache server.
  • 01173_transaction_control_queries and 01168_mutations_isolation (private flaky check): they run only because this PR edits their tag lines, and the private CI counts them as known failures.

All public CI jobs passed.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (8b5f2f93125) with no conflicts. The PR diff is unchanged and Planner.cpp builds. Public CI was green on 59415bd73b7. The only red check was CH Inc sync ("tests failed"), and none of its failures come from this change:

I asked for these to be investigated on the sync PR.

…o-read-setting

`collectFiltersForAnalysis` moved from `Planner.cpp` to `PlannerSteps.cpp` on master;
the PR's `keep_logical_steps = true` change is ported there.

This branch has not been deployed

No deployments
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-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants