Skip to content

Automatically adjust settings when make_distributed_plan is enabled - #112463

Merged
alesapin merged 5 commits into
masterfrom
auto-settings-make-distributed-plan
Jul 31, 2026
Merged

alesapin merged 5 commits into
masterfrom
auto-settings-make-distributed-plan

Conversation

@alesapin

@alesapin alesapin commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Now make_distributed_plan=1 will disable not yet supported features. Fixes #109476.

Version info

  • Merged into: 26.8.1.506 (included in 26.8 and later)

alesapin and others added 2 commits July 29, 2026 18:11
When `make_distributed_plan = 1`, several features are not supported by
distributed query plans yet. Instead of failing during planning or
execution, automatically adjust the settings that control them:
- `enable_parallel_replicas = 0` and `automatic_parallel_replicas_mode = 0`
  (previously the combination was rejected with `SUPPORT_IS_DISABLED`)
- `rewrite_in_to_join = 1`, which makes `IN (subquery)` distributable
  (only when `allow_experimental_correlated_subqueries` is enabled)
- `correlated_subqueries_use_in_memory_buffer = 0` (its steps are not
  serializable for remote execution)
- `use_skip_indexes_on_data_read = 0`
- `compile_expressions = 0`
- `query_plan_direct_read_from_text_index = 0`, which fixes
  `NOT_FOUND_COLUMN_IN_BLOCK` on full-text search queries

The switch is applied on the initiator in
`InterpreterSelectQueryAnalyzer::buildContext` and re-applied on worker
task contexts in `doExecuteTask`, because task contexts are rebuilt from
the initiator's user-level settings changes and do not see the
initiator-side overrides.

Closes: #109476
Closes: #109329

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [48b17e1]

Summary: ✅


AI Review

Summary

This PR makes make_distributed_plan auto-adjust several incompatible settings instead of throwing on them. The main idea is sound, but the current implementation still misses one settings-mutation carrier (... = DEFAULT) and mutates session/profile state one-way, so the advertised "auto-adjust while distributed plans are enabled" contract is not actually preserved across ordinary settings workflows. The published setting docs are also still stale.

Findings

❌ Blockers

  • [src/Interpreters/Context.cpp:3483, src/Interpreters/InterpreterSetQuery.cpp:50] SET ... = DEFAULT bypasses adjustSettingsForMakeDistributedPlan. InterpreterSetQuery applies ast.changes through applySettingsChanges, but then resetSettingsToDefaultValue just calls settings->setDefaultValue(name) and stops. Under make_distributed_plan = 1, SELECT ... SETTINGS query_plan_direct_read_from_text_index = DEFAULT, SET compile_expressions = DEFAULT, etc. restore the default-on values that this PR is supposed to force off, so unsupported distributed-plan paths are still reachable through ordinary SQL syntax.

  • [src/Core/SettingsQuirks.cpp:105] The helper only pushes dependent settings toward distributed-plan-safe values; it never restores them when the reason for the override disappears. After SET make_distributed_plan = 1 followed by SET make_distributed_plan = 0, the session/profile keeps rewritten values such as compile_expressions = 0, use_skip_indexes_on_data_read = 0, and rewrite_in_to_join = 1. The same one-way leak also leaves an inconsistent state if allow_experimental_correlated_subqueries is turned back off while make_distributed_plan stays on: rewrite_in_to_join remains 1, and then IN (subquery) starts throwing because resolveFunction requires allow_experimental_correlated_subqueries. That silently changes later non-distributed queries and makes the workaround escape the scope promised by make_distributed_plan.

⚠️ Majors

  • [src/Core/Settings.cpp:8469, docs/reference/settings/session-settings/other.mdx:781] The server-side help text now documents the automatic rewrites, but the published make_distributed_plan page still only says "Make distributed query plan." Users reading the docs will not learn that enabling this setting also flips enable_parallel_replicas, automatic_parallel_replicas_mode, rewrite_in_to_join, correlated_subqueries_use_in_memory_buffer, use_skip_indexes_on_data_read, compile_expressions, and query_plan_direct_read_from_text_index.
Final Verdict

❌ Changes requested. The PR’s core contract is still violated by DEFAULT resets and by the one-way mutation of session/profile settings, so I would not merge it until those paths are made reversible/consistent and the published setting docs are updated.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jul 29, 2026
@davenger davenger self-assigned this Jul 29, 2026
Comment thread src/Core/Settings.cpp
@@ -8469,6 +8469,14 @@ Method to compress `.metadata.json` file.
)", EXPERIMENTAL) \

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.

The server-side help string is updated here, but the published docs are still stale: docs/reference/settings/session-settings/other.mdx#make_distributed_plan currently only says “Make distributed query plan.” After this PR, enabling make_distributed_plan also silently flips several other session settings (enable_parallel_replicas, automatic_parallel_replicas_mode, rewrite_in_to_join, compile_expressions, etc.), so users need that behavior documented in the settings page too, not only in the in-server description.

A per-SELECT SETTINGS clause is re-applied onto the query's own context
during query tree building, which restored the unsupported settings and
made the CI settings randomizer reach the parallel replicas rejection
through a plan with a local parallel replica read.

Move the auto-switch from InterpreterSelectQueryAnalyzer::buildContext
and doExecuteTask into adjustSettingsForMakeDistributedPlan, applied in
Context::applySettingsChangesWithLock next to applySettingsQuirks. Every
context that drives analysis, planning or task execution goes through
it: the initiator query context, per-SELECT settings re-application,
session-level SET, EXPLAIN's inner settings, and the worker's context
rebuilt from the initiator's settings changes.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112463&sha=1c1b45372a46c1d07830635edff9a9ca0742eac4&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29
PR: #112463

Co-Authored-By: Claude Fable 5 <[email protected]>
for (const SettingChange & change : changes)
applySettingChangeWithLock(change, lock);
applySettingsQuirks(*settings);
adjustSettingsForMakeDistributedPlan(*settings);

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.

adjustSettingsForMakeDistributedPlan only runs after applySettingsChanges, but SQL ... = DEFAULT takes a different path: InterpreterSetQuery::executeForCurrentContext applies ast.changes first and then calls resetSettingsToDefaultValue(ast.default_settings), and Context::resetSettingsToDefaultValue just does settings->setDefaultValue(name) without re-running this hook. That means SELECT ... SETTINGS query_plan_direct_read_from_text_index = DEFAULT (or SET compile_expressions = DEFAULT, etc.) under make_distributed_plan = 1 restores the default-true settings that this PR is trying to force off, so the old unsupported distributed-plan paths are still reachable through DEFAULT.

This needs the same post-processing after default resets too, or a shared helper that all settings mutations (applySettingsChanges, setSetting, default resets) go through. A focused stateless regression on one ... = DEFAULT case would keep this covered.

Comment thread src/Core/SettingsQuirks.cpp Resolved
…query test

The randomizer disables it in 5% of runs; the decorrelated correlation
condition then stays a filter above a CROSS JOIN and the scalar
aggregate queries become quadratic (10k x 10k = 100M join rows,
JoinResultRowCount confirmed in query_log), running for 140-235 seconds
under TSan with make_distributed_plan both 0 and 1 and exceeding the
180-second limit of the flaky check. 03734_correlated_subqueries_reorder
pins the same setting for the same reason.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112463&sha=eeec1ed63d302174d68deb799222c937410a1ba9&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29
PR: #112463

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.60% 78.60% +0.00%

Changed lines: Changed C/C++ lines covered: 53/53 (100.00%) · Uncovered code

Full report · Diff report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

make it worse pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically change some settings if make_distributed_plan=1 is enabled

3 participants