Skip to content

Allow unknown settings in query plan serialization - #115627

Closed
vdimir wants to merge 2 commits into
masterfrom
vdimir/tolerant-query-plan-settings
Closed

vdimir wants to merge 2 commits into
masterfrom
vdimir/tolerant-query-plan-settings

Conversation

@vdimir

@vdimir vdimir commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Related: #114184

Adding a plan setting has meant bumping DBMS_QUERY_PLAN_SERIALIZATION_VERSION and gating the write on it — twice already, for versions 5 and 7 — because the settings of a step were written as a name and a typed binary value. A reader that met a name it did not know could not tell where the value ended, so QueryPlanSerializationSettings::readBinary threw UNKNOWN_SETTING. That fenced off far more than the feature being added: the name goes into every plan that touches the step, so a setting a given plan cannot even use made that plan unreadable to the previous release. Fencing a feature is what the step registry does, by rejecting an unknown step.

Plan settings are now written the way query settings have always travelled between client and server (SettingsWriteFormat::STRINGS_WITH_FLAGS): name, flags, and the value as a string of its own length. A reader steps over a name it does not know and keeps its own default for it, and rejects the plan only when the name carries IMPORTANT — the flag that already means "affects query results, cannot be ignored by older versions". Which form is written is decided by the version of the stream, which QueryPlan::serialize already negotiates as the minimum of ours and the peer's, so a peer below version 9 keeps receiving the old form and nothing changes for it.

The plan settings that decide a result rather than a way of producing it are marked IMPORTANT accordingly: the row and byte limits of DISTINCT, ORDER BY, GROUP BY and JOIN with their overflow modes, the two-level aggregation thresholds, empty_result_for_aggregation_by_empty_set, join_any_take_last_row, totals_auto_threshold, and the two settings that decide how aggregation states are laid out. The existing per-setting gates stay — peers below version 9 still need them — but a setting added from now on needs one only when it belongs in that group.

gtest_query_plan_settings_skippable covers the round trip of every declared setting type through its string form, the old form at the previous version, an unknown setting being skipped, and an unknown IMPORTANT setting being rejected. The 58 stateless tests that set serialize_query_plan were run against the new format locally (56 pass; two fail only for want of s3_disk and https_port in the local server config).

Changelog category (leave one):

  • Improvement

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

A query plan serialized with serialize_query_plan = 1 no longer becomes unreadable to a peer that does not know one of the plan's settings: a setting the peer can ignore is skipped, and only one whose absence would change the query result is rejected.


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

Adding a plan setting has meant bumping `DBMS_QUERY_PLAN_SERIALIZATION_VERSION` and gating the write
on it, twice already (versions 5 and 7), because the settings of a step were written as a name and a
typed binary value: a reader that met a name it did not know could not tell where the value ended, so
`readBinary` threw `UNKNOWN_SETTING` on it. That fenced off far more than the feature - the name is
written into every plan that touches the step, so a setting the plan cannot even use made the plan
unreadable to the previous release.

Write them the way query settings have always travelled between client and server instead: name,
flags, and the value as a string of its own length. A reader can then step over a name it does not
know and keep its own default for it, and rejects the plan only when the name carries `IMPORTANT` -
the flag that says ignoring the setting would change what the query returns. Both directions are
chosen by the version the stream is written with, which `Serialization.cpp` already negotiates as the
minimum of ours and the peer's, so a peer below version 10 keeps receiving the old form.

The plan settings that decide a result rather than a way of producing it are marked `IMPORTANT`
accordingly: the row and byte limits of `DISTINCT`, `ORDER BY`, `GROUP BY` and `JOIN` with their
overflow modes, the two-level aggregation thresholds, `empty_result_for_aggregation_by_empty_set`,
`join_any_take_last_row`, `totals_auto_threshold`, and the two settings that decide how aggregation
states are laid out. The existing per-setting gates stay: they are what peers below version 10 need.

A new setting after this needs a gate of its own only when it belongs in that first group.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@vdimir
vdimir force-pushed the vdimir/tolerant-query-plan-settings branch from 1f1fafe to 01c704f Compare August 20, 2026 14:10
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9d113a9]

Summary: ❌

job_name test_name status info comment
Stress test (arm_debug) FAIL
Logical error: Block structure mismatch in A stream: different names of columns: (STID: 0993-30f7) FAIL cidb

AI Review

Summary

This PR switches query-plan setting serialization to the string-and-flags format used by query settings so newer plans can skip unknown non-semantic settings instead of failing on UNKNOWN_SETTING, and it marks result/layout-affecting settings as IMPORTANT. The compatibility direction is sound, but two issues remain: the new skip path currently logs expected unknown settings as warnings, and the updated version-11 contract still overstates when future settings can drop their pre-11 version gates.

Missing context / blind spots
  • ⚠️ The available Praktika data only includes Build profile diff; I did not have green functional CI coverage for the new query-plan serialization path beyond the unit tests added in this PR.
Findings

⚠️ Majors

  • [src/Processors/QueryPlan/QueryPlanSerializationSettings.cpp:156-157] The new impl->read(..., SettingsWriteFormat::STRINGS_WITH_FLAGS) path inherits BaseSettingsHelpers::warningSettingNotFound, so the first later release that adds a non-IMPORTANT plan setting will make every older worker log Unknown settings: ... for each affected deserialized step/query during mixed-version rollouts. That turns the intended compatibility path into warning-log spam instead of a silent skip. Suggested fix: add a QueryPlanSerializationSettings-specific string reader, or a suppression mode in BaseSettings::read, that still rejects unknown IMPORTANT settings but skips ignorable ones without warning.
  • [src/Core/ProtocolDefines.h:99-104, src/Processors/QueryPlan/tests/gtest_query_plan_settings_skippable.cpp:29-33] The new version-11 contract still says a setting added after this version needs its own gate only when ignoring it would change results. That is still false for peers below DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_SKIPPABLE_SETTINGS: version negotiation drops them onto the legacy named-binary format, where any unknown name still throws before IMPORTANT can help. The same incorrect rule is repeated in the new test comment, so it is easy for the next contributor to remove a required pre-11 gate and break mixed-version distributed queries. Suggested fix: say explicitly that IMPORTANT only replaces per-setting gates once the negotiated version is at least DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_SKIPPABLE_SETTINGS; older peers still need explicit guards.
Final Verdict

Changes requested. The mixed-version compatibility contract is not fully documented yet, and the new deserialization path will warn on the very skips it is supposed to treat as routine.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.10% 87.00% -0.10%
Functions 91.90% 91.90% +0.00%
Branches 79.40% 79.30% -0.10%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 20, 2026
@vdimir vdimir changed the title Let a query plan carry a setting a peer does not know Allow unknown settings in query plan serialization Aug 20, 2026
/// Version 10 changes how the plan settings of a step are written: as name, flags and a length-prefixed
/// value, the format query settings have always used between client and server, instead of a name and a
/// typed binary value. A reader can then step over a setting it does not know, so a setting introduced
/// after this version needs a gate of its own only when the receiver ignoring it would change the

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 new wire format only solves the UNKNOWN_SETTING problem once the negotiated plan version is already >= DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_SKIPPABLE_SETTINGS. If a future release adds a new “performance-only” plan setting and follows this comment literally, talking to a 25.8 peer will still negotiate version == 9, writeChangedBinary will fall back to the legacy named-binary form, and that peer will throw on the new name before it has any chance to skip it.

So post-10 settings still need a < DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_SKIPPABLE_SETTINGS guard for pre-10 peers; only peers that already negotiated the skippable format can rely on IMPORTANT to choose skip vs reject. Please keep that part of the contract explicit here (and in the new test comment), otherwise the next setting added under this rule will regress mixed-version distributed queries.

@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 9d113a9d8 with master c9207f0ac (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
Binary Master PR Δ
programs/clickhouse-stripped 704.41 MiB 701.39 MiB -3.02 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

6 object files changed (+19.70 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/QueryPlan/QueryPlanSerializationSettings.cpp.o 225.71 KiB 245.38 KiB +19.67 KiB (+8.71%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

{
impl->readBinary(in);
if (version >= DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_SKIPPABLE_SETTINGS)
impl->read(in, SettingsWriteFormat::STRINGS_WITH_FLAGS);

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 new STRINGS_WITH_FLAGS path inherits BaseSettings::read, which treats every skipped unknown name as a warning via BaseSettingsHelpers::warningSettingNotFound. After this PR, though, unknown non-IMPORTANT plan settings are the expected mixed-version path. As soon as a later release adds a performance-only plan setting, every older worker will start logging Unknown settings: ... once per deserialized step/query even though the plan is supposed to be accepted silently. This needs a QueryPlanSerializationSettings-specific reader, or a suppression mode in BaseSettings::read, that still rejects unknown IMPORTANT settings but skips ignorable ones without warning-level log spam.

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 35 queries analysed

This PR changes how query-plan settings are serialized between nodes to a skippable string-and-flags wire format (a protocol/compatibility change). That code runs once per distributed query at plan setup and does not touch the join, aggregation, or sort operators that TPC-H Q7 and Q17 actually execute, so it cannot plausibly move their per-query timings by tens of milliseconds. Q17's flagged +57.8% is downgraded to not_sure: the change is off the query's execution path and its underlying measurements were noisy (borderline right at the top of master's variance band). Q7 stays not_sure inside master's variance band with flat CPU. No real per-query regression is attributable to this PR.

clickbench

🟢 No significant changes

tpch_adapted_1_official

⚠️ 2 inconclusive

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 7 not_sure 67 78 +16.4% <0.0001 join_operator: Delta sits inside master's variance band with essentially flat CPU, and this settings-serialization change does not touch Q7's join execution. Reads as run-to-run variance.
⚠️ 17 not_sure 64 101 +57.8% <0.0001 join_operator: This PR only changes the wire format of query-plan settings, done once per distributed query at plan setup, not Q17's join/aggregation execution. The measurements were noisy, so this +57.8% reads as variance.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: af0b3a80-ea54-4d0b-a0bc-f4858ff893e3
  • MIRAI run: 7093c429-d5a1-4c1c-a787-47105140ddfb
  • PR check IDs:
    • clickbench_411400_1787310762
    • clickbench_411406_1787310762
    • clickbench_411418_1787310762
    • tpch_adapted_1_official_411429_1787310762
    • tpch_adapted_1_official_411444_1787310762
    • tpch_adapted_1_official_411470_1787310762

@vdimir
vdimir marked this pull request as draft August 25, 2026 10:43
@clickhouse-gh clickhouse-gh Bot added the comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... label Sep 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Dear @vdimir, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

@vdimir vdimir closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant