Skip to content

Preserve SettingFieldMaxThreads::is_auto across SET <name> = DEFAULT - #103991

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-103120-setting-default-roundtrip
May 6, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-103120-setting-default-roundtrip

Conversation

@groeneai

@groeneai groeneai commented May 4, 2026

Copy link
Copy Markdown
Collaborator

Fixes #103120.

SET max_threads = DEFAULT (and the same for max_final_threads and max_parsing_threads) used to lose the is_auto flag for SettingFieldMaxThreads-typed settings. After the reset, system.settings would report 32 instead of 'auto(32)', and the runtime would behave as if the user had explicitly pinned max_threads to the resolved core count.

Root cause

BaseSettings::resetValueToDefault (src/Core/BaseSettings.h) round-tripped the default value through Field:

auto p = field_infos[index].create_default_function();
*field_infos[index].get_data_function(...) = static_cast<Field>(*p);

For SettingFieldMaxThreads, operator Field() returns the resolved auto-value (the value member, e.g. 32), not the canonical 0 that the constructor maps back to auto. The destination's operator=(const Field &) then calls fieldToMaxThreads(Field(32)) -> operator=(UInt64 32) -> is_auto = !32 = false. The Field round-trip is not invertible, and the auto state is permanently lost.

Fix

Replace the lossy Field round-trip with a per-setting reset_function lambda generated by the same macro that emits get_data_function / create_default_function:

[](Data & data) { data.NAME = SettingField##TYPE(DEFAULT); data.NAME.setChanged(false); }

Typed copy assignment goes through the setting type's own operator=, so all type-specific state is preserved (is_auto for SettingFieldMaxThreads, plus any future internal flags on other types). The change is structural - it eliminates the entire class of non-invertible-Field reset bugs rather than patching a single symptom in one type.

The change touches only the macro that builds FieldInfo and the resetValueToDefault accessor, so it applies uniformly to every settings group (regular Settings, MergeTreeSettings, KafkaSettings, etc.).

Test

tests/queries/0_stateless/04202_set_default_preserves_max_threads_auto.sql covers:

  • single-setting SET <name> = DEFAULT for all three SettingFieldMaxThreads settings,
  • multi-setting SET a = DEFAULT, b = DEFAULT, ... form,
  • idempotent reset (DEFAULT applied twice still yields auto),
  • a SettingAutoWrapper control (query_plan_join_swap_table) that must remain correct,
  • a regular numeric setting control (max_block_size) for the changed flag.

The test starts by resetting the three settings to DEFAULT so it is robust against the test runner's session-level randomization. On a buggy build the test fails on the first three assertions; on the patched build it passes (verified locally with --test-runs 50 under full CI randomization).

cc @Algunenano - per your request on #103120.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

SET max_threads = DEFAULT (and the same for max_final_threads and max_parsing_threads) no longer loses the auto state. Previously, after resetting one of these settings, system.settings would report the resolved core count (e.g. 32) instead of 'auto(32)', and the server would behave as if the value had been explicitly pinned.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

`BaseSettings::resetValueToDefault` previously round-tripped the default
value through `static_cast<Field>(*default_setting)` followed by
`operator=(const Field &)` on the destination. For
`SettingFieldMaxThreads`, this round-trip is not invertible:
`operator Field()` returns the resolved auto-value (e.g. `32`), so
applying it back via `operator=(const Field &)` reaches
`fieldToMaxThreads(Field(32))` -> `operator=(UInt64 32)` and clears
`is_auto`. After `SET max_threads = DEFAULT`, `system.settings` would
report `32` instead of `'auto(32)'`. The same bug affected
`max_final_threads` and `max_parsing_threads`.

Replace the lossy Field round-trip with a per-setting `reset_function`
lambda that performs typed copy assignment via the setting's own
`operator=`: `data.NAME = SettingField##TYPE(DEFAULT);` followed by
`setChanged(false)`. Typed assignment preserves all type-specific state
(`is_auto`, plus any future internal flags) and is correct for every
existing `SettingField` type. The fix is structural - it removes the
entire class of non-invertible-Field bugs rather than patching a single
symptom.

The new test
`tests/queries/0_stateless/04202_set_default_preserves_max_threads_auto.sql`
covers the three affected `SettingFieldMaxThreads` settings, the
single-setting and multi-setting forms of `SET ... = DEFAULT`,
idempotent reset, and control assertions for `SettingAutoWrapper` and a
regular numeric setting.

Closes ClickHouse#103120
@groeneai

groeneai commented May 4, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (per task-worker policy):

(a) Deterministic repro? Yes. On master HEAD d8baabb6c7e2:

SET max_threads = 4;
SET max_threads = DEFAULT;
SELECT value FROM system.settings WHERE name = 'max_threads';
-- master:  32          <- bug: is_auto lost
-- patched: 'auto(32)'  <- fixed

Reproduces 100% of the time on the reporter's exact reproducer.

(b) Root cause explained? Yes. BaseSettings::resetValueToDefault round-trips the default through static_cast<Field>(*p) followed by operator=(const Field &). For SettingFieldMaxThreads, operator Field() returns value (the resolved auto-value, e.g. 32), not 0. The destination's operator=(const Field &) -> fieldToMaxThreads(Field(32)) -> operator=(UInt64 32) -> is_auto = !32 = false. The Field round-trip is non-invertible, so the auto state is permanently lost.

(c) Fix matches root cause? Yes. The fix replaces the lossy Field round-trip with a per-setting reset_function lambda that performs typed copy assignment via the setting's own operator=. This preserves all type-specific state and is structural - it removes the entire class of non-invertible-Field reset bugs rather than patching the one symptom in SettingFieldMaxThreads. Every setting type benefits, with no behavioural change for types whose operator Field() is already invertible.

(d) Test intent preserved? N/A - this is a brand-new test. It is robust against CI session-level randomization (it starts by resetting all three settings to DEFAULT) and asserts both the auto state of the SettingFieldMaxThreads settings and a SettingAutoWrapper control plus a regular-numeric control to catch regressions in the unaffected paths.

(e) Both directions demonstrated?

  • Without fix (master HEAD d8baabb6c7e2): test fails with diff showing exactly the is_auto loss in the after-default and multi-default rows.
  • With fix: test passes 50/50 with full CI randomization (tests/clickhouse-test --test-runs 50 04202_set_default_preserves_max_threads_auto).

(f) General, not narrow patch? Yes. The change is to the macro that emits FieldInfo for every settings group, so it applies uniformly to Settings, MergeTreeSettings, KafkaSettings, etc. It fixes all three affected SettingFieldMaxThreads settings (max_threads, max_final_threads, max_parsing_threads) and prevents future SettingField types with non-invertible operator Field() from hitting the same bug. Settings-related sanity tests (02326_settings_changes_system_table, 02995_new_settings_history, 00167_settings_inside_query, 01283_max_threads_simple_query_optimization, 03148_setting_max_streams_to_max_threads_ratio_overflow) all pass on the patched build.

Session: cron:clickhouse-ci-task-worker:20260504-091500.

@groeneai

groeneai commented May 4, 2026

Copy link
Copy Markdown
Collaborator Author

@Algunenano - PR is up per your request on #103120. Ready for review.

cc @vitlibar as the other listed expert for comp-settings in component-tree.yaml.

@Algunenano Algunenano self-assigned this May 4, 2026
@Algunenano Algunenano added the can be tested Allows running workflows for external contributors label May 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [eb131f0]

Summary: ✅


AI Review

Summary

This PR fixes loss of SettingFieldMaxThreads::is_auto on SET <name> = DEFAULT by adding a typed reset hook (SettingFieldBase::resetFromDefault) and overriding it for SettingFieldMaxThreads to preserve internal state instead of relying on a lossy Field round-trip. The change is focused, keeps operator Field backward-compatible (numeric), and includes a strong stateless regression test covering both auto-default and explicit-default MaxThreads settings.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 4, 2026
Comment thread src/Core/BaseSettings.h Resolved
Per @Algunenano's review feedback on PR ClickHouse#103991, replace the per-setting
`reset_function` lambda with a structurally smaller fix: have
`SettingFieldMaxThreads::operator Field` return the canonical `"auto"` keyword
when `is_auto` is set, mirroring `SettingAutoWrapper::operator Field`.

This makes the `Field` round-trip in `BaseSettings::resetValueToDefault`
(and any other code path that round-trips through `Field`) invertible:
`fieldToMaxThreads(Field("auto"))` parses back to the canonical 0, and
`SettingFieldMaxThreads::operator=(UInt64(0))` sets `is_auto = true` and
recomputes `value = getAuto()`. No changes to `BaseSettings.h` are needed.

Why this is correct:

* `SettingAutoWrapper` already uses this pattern for its own auto/keyword
  duality, so the round-trip is invertible there. The bug existed only
  for `SettingFieldMaxThreads`, which is a separate type.
* `writeBinary` already canonicalizes to 0 (`writeVarUInt(is_auto ? 0 : value)`),
  so the binary serialization path was already invertible. The fix aligns the
  Field path with the binary path.
* `system.settings` reads via `getValueString` -> `toString`, which still
  prints `'auto(N)'` and is therefore unaffected.
* Distributed forwarding uses `STRINGS_WITH_FLAGS` (calls `toString`) or the
  legacy binary format (calls `writeBinary`); neither uses `operator Field`.

Why this is smaller / cheaper than the previous lambda-based fix:

* Reverts the per-setting `reset_function` lambda generated by the
  `IMPLEMENT_SETTINGS_TRAITS_` macros — no extra code generated for the
  ~1000+ settings across `Settings`, `MergeTreeSettings`, `KafkaSettings`, etc.
* Removes the extra `reset_function` field from `FieldInfo`.
* Net diff: 1 functional line in `SettingsFields.h` (plus comment).

Verified locally: 50/50 passes with full CI randomization on the regression
test, plus all related stateless tests (`02995_new_settings_history`,
`02992_settings_overflow`, `00282_settings_default`, all `max_threads`
stateless tests). Manual repro of the bug now restores `'auto(N)'` after
`SET max_threads = DEFAULT` for all three `MaxThreads` settings.

Closes ClickHouse#103120 (alongside the prior commit on this PR).
Comment thread src/Core/SettingsFields.h Resolved
This replaces the previous attempt that made `operator Field` return
`Field("auto")` for the auto state. That approach was correct in spirit
but backward-incompatible: `SettingFieldMaxThreads` is documented as
behaving like a regular `UInt64` for compatibility, and code reading
`getSetting('max_threads')` as numeric would observe a String type
when the setting is in the default state.

Reverts `operator Field` to its master form (`return value;`).

Instead, override `SettingFieldMaxThreads::setChanged(bool)` to restore
the canonical default state (`is_auto = true; value = getAuto();`) when
called with `false`. `BaseSettings::resetValueToDefault`
(`src/Core/BaseSettings.h:1151`) is the only caller of `setChanged(false)`
in the tree -- a `grep -rn 'setChanged\s*(' src/ programs/ base/`
confirms zero other call sites -- so the hook only fires on the
`SET <name> = DEFAULT` path that has the bug. No per-setting lambdas,
no `FieldInfo` enlargement, no public-API change.

Per @Algunenano's directive on the inline review thread of this PR.

Issue: ClickHouse#103120
Comment thread src/Core/SettingsFields.h Outdated
changed = changed_;
if (!changed_)
{
is_auto = true;

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.

setChanged(false) is used for all SettingFieldMaxThreads settings, but this override always restores auto (is_auto = true; value = getAuto()). That silently changes semantics for settings whose default is an explicit number, not auto.

Concrete example in this PR: max_download_threads is declared as DECLARE(MaxThreads, max_download_threads, 4, ...) in src/Core/Settings.cpp. With this change:

  • SET max_download_threads = 1;
  • SET max_download_threads = DEFAULT;

will reset to auto(N) instead of the declared default 4. So the fix for max_threads regresses other MaxThreads settings.

Could we restore the typed default value here (or in resetValueToDefault) instead of hard-coding the auto state?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Replaced the setChanged hook with a typed-copy override of a new SettingFieldBase::resetFromDefault virtual in eb131f01. setChanged is now byte-identical to master (just changed = changed_;); max_download_threads is preserved because typed copy reproduces the declared default member-wise, including is_auto = false, value = 4.

Test extended to lock the spec for both default kinds: a max_download_threads = 0 (switches to auto) -> SET max_download_threads = DEFAULT (must restore 4, not stay auto) sequence catches exactly this regression class.

@Algunenano

Copy link
Copy Markdown
Member

@groeneai We need a comprehensive test of how thing should work because the AI reviewer keeps finding corner cases. Let's add tests for other settings, include checks with getSetting and so on

…ads::is_auto

Previous attempts:
- 15ad0c6: per-setting reset_function lambda - rejected by reviewer (build/code bloat)
- fc9a691: operator Field returned String("auto") - rejected by AI reviewer (changes the
  Field type observed by getSetting('max_threads') from numeric to string)
- 985be25: setChanged(false) hard-coded is_auto = true - rejected by AI reviewer because
  max_download_threads is also a SettingFieldMaxThreads with declared default 4 (NOT auto),
  so the hard-coded auto-restoration regressed it to 'auto(N)' on SET = DEFAULT

This iteration takes the AI reviewer's "restore the typed default value" recommendation
literally, by routing the reset through a typed copy instead of a Field round-trip:

- Add `SettingFieldBase::resetFromDefault(const SettingFieldBase &)`. Default implementation
  matches the previous Field round-trip (`*this = static_cast<Field>(other); setChanged(false);`),
  so every type whose `operator Field` is invertible keeps its current behaviour and no
  per-setting code is generated.
- Override in `SettingFieldMaxThreads` to copy member-wise via the existing typed
  `operator=(const SettingFieldMaxThreads &)`. This preserves whichever state the typed
  default carries: `is_auto = true, value = getAuto()` for settings declared with default `0`
  (`max_threads`, `max_final_threads`, `max_parsing_threads`), and `is_auto = false, value = 4`
  for `max_download_threads`. No special-casing or hard-coded auto state.
- `BaseSettings::resetValueToDefault` dispatches through the new virtual instead of inlining
  the Field round-trip, so each type chooses for itself.

`operator Field` is unchanged (still `return value`), so `getSetting('max_threads')` keeps
returning a numeric `Field` and there is no backward-incompatible change for callers that
treat `max_threads` as `UInt64`. The diff in `BaseSettings.h` is one line of behaviour change
(no per-setting codegen), and `SettingsFields.h` adds one virtual method on the base and one
override on `SettingFieldMaxThreads`.

Closes ClickHouse#103120.

Comprehensive regression test in `04202_set_default_preserves_max_threads_auto.sql` covers
all four `SettingFieldMaxThreads` settings with their distinct declared defaults (auto-default
and explicit-default groups), the multi-setting `SET a = DEFAULT, b = DEFAULT` form,
idempotent resets, the `0` <-> auto transition for `max_download_threads`, `getSetting`
return-type checks (`UInt`-family), and `SettingAutoWrapper` / `SettingFieldNumber` controls.
50/50 passes locally with full CI randomization.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@groeneai

groeneai commented May 4, 2026

Copy link
Copy Markdown
Collaborator Author

@Algunenano done in eb131f01 — pinning the spec via tests first, then replacing the setChanged hook with a typed-copy mechanism that also handles max_download_threads correctly.

Comprehensive test (tests/queries/0_stateless/04202_set_default_preserves_max_threads_auto.sql)

Now covers every SettingFieldMaxThreads setting in the tree across both default kinds and adds explicit getSetting invariants:

  • max_threads, max_final_threads, max_parsing_threads (declared default 0 -> auto): assert 'auto(N)' after initial reset, after explicit-then-DEFAULT, idempotent DEFAULT, and the multi-setting SET a = DEFAULT, b = DEFAULT form.
  • max_download_threads (declared default 4, NOT auto): assert value = 4 after initial reset, after SET = 1 then SET = DEFAULT, AND after the SET = 0 (switches to auto) -> SET = DEFAULT (must restore 4, not stay auto). This last case is what the previous setChanged-based attempt regressed.
  • getSetting numeric invariant: startsWith(toTypeName(getSetting('<name>')), 'UInt') for every SettingFieldMaxThreads setting in both default and explicit states, plus a value check for max_download_threads. Pinned with startsWith rather than exact toTypeName because the analyzer narrows UInt64 literals to the smallest fitting UInt8/UInt16 based on the resolved auto value, but the type family must remain UInt.
  • Controls: query_plan_join_swap_table (SettingAutoWrapper<SettingFieldBool>, the documented "real auto" type) preserves the auto keyword across DEFAULT, and max_block_size (regular SettingFieldNumber<UInt64>) round-trips changed = 0 correctly.

50/50 passes locally with full CI randomization.

Fix (src/Core/SettingsFields.h + src/Core/BaseSettings.h)

Reverted commit 985be25a (setChanged hook). The bot was right that hard-coding is_auto = true on setChanged(false) regressed max_download_threads = DEFAULT from 4 to 'auto(N)'. Replaced it with the AI reviewer's literal recommendation - "restore the typed default value" - via a typed copy:

struct SettingFieldBase
{
    // ... existing virtuals ...

    /// Default impl: Field round-trip + setChanged(false). Suits any type whose `operator Field`
    /// is invertible. Override in types where the round-trip would lose state.
    virtual void resetFromDefault(const SettingFieldBase & default_value)
    {
        *this = static_cast<Field>(default_value);
        setChanged(false);
    }
};

struct SettingFieldMaxThreads final : SettingFieldBase
{
    // setChanged is back to plain `changed = changed_;` (byte-identical to master).

    void resetFromDefault(const SettingFieldBase & default_value) override
    {
        *this = static_cast<const SettingFieldMaxThreads &>(default_value);
        changed = false;
    }
};

BaseSettings::resetValueToDefault dispatches through the virtual instead of inlining the Field round-trip. No per-setting codegen - the macro expansion in IMPLEMENT_SETTINGS_TRAITS_ is unchanged, so the bloat concern that killed 15ad0c6f (per-setting reset_function lambdas) does not return: there is exactly one extra vtable slot per SettingField type, not per setting.

Why this addresses every concern raised so far on this PR:

  1. No build/code bloat (your original feedback on 15ad0c6f). One virtual on the base, one override on SettingFieldMaxThreads. The macro that expands per setting is byte-identical to master.
  2. operator Field unchanged (the bot's feedback on fc9a6917). Still returns value, so getSetting('max_threads') is still numeric. Distributed forwarding (STRINGS_WITH_FLAGS and legacy binary) is unaffected.
  3. max_download_threads preserved (the bot's feedback on 985be25a). Typed copy reproduces the typed default verbatim, so is_auto = false, value = 4 for max_download_threads and is_auto = true, value = getAuto() for the three auto-defaulted settings, with no setting-name-aware special casing.
  4. General mechanism, not a one-off patch. Future SettingField types that deliberately have a non-invertible operator Field (the issue's "open risks" note) just override resetFromDefault.

cc @vitlibar.

@groeneai

groeneai commented May 4, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (per task-worker policy, against eb131f01):

(a) Deterministic repro? Yes. On master HEAD d8baabb6c7e2:

SET max_threads = 4;
SET max_threads = DEFAULT;
SELECT value FROM system.settings WHERE name = 'max_threads';
-- master: '4'  (BUG, drops is_auto)
-- with fix: ''auto(N)'' (correct)

SET max_download_threads = 0;
SET max_download_threads = DEFAULT;
SELECT value FROM system.settings WHERE name = 'max_download_threads';
-- master: '4' (correct)
-- broken setChanged hook (985be25a): ''auto(N)'' (REGRESSION)
-- with fix: '4' (correct)

(b) Root cause explained? Yes. BaseSettings::resetValueToDefault round-trips the typed default through Field. SettingFieldMaxThreads::operator Field returns the resolved value (not the canonical 0 / "auto") by design - it deliberately behaves like a plain UInt64 so getSetting('max_threads') stays numeric. The receiving operator=(const Field &) then calls fieldToMaxThreads(Field(N)) -> operator=(UInt64 N) -> is_auto = !N, dropping the auto state for any auto-resolved value N > 0. Settings declared with default 0 (auto) lose is_auto; settings declared with explicit non-zero defaults (max_download_threads = 4) are unaffected by the original bug because their default already has is_auto = false.

(c) Fix matches root cause? Yes. The lossy step is the Field round-trip itself. Replacing it with typed copy via SettingFieldBase::resetFromDefault (default impl keeps the existing Field path; SettingFieldMaxThreads overrides to use the typed operator=) fixes the mechanism, not a symptom. Importantly, the fix does NOT involve any setting-name awareness, hard-coded auto state, or change to operator Field.

(d) Test intent preserved? / New tests added? New comprehensive test 04202_set_default_preserves_max_threads_auto.sql covers:

  • All four SettingFieldMaxThreads settings in both default kinds (max_threads, max_final_threads, max_parsing_threads - default 0/auto; max_download_threads - default 4/explicit).
  • Multi-setting SET a = DEFAULT, b = DEFAULT form.
  • Idempotent DEFAULT.
  • The 0 -> auto -> DEFAULT sequence on max_download_threads that catches the broken-setChanged regression class.
  • getSetting numeric invariant (UInt-family) for every SettingFieldMaxThreads setting in default and explicit states.
  • Controls: query_plan_join_swap_table (SettingAutoWrapper) preserves auto keyword; max_block_size (regular SettingFieldNumber) round-trips changed = 0.

(e) Both directions demonstrated? Yes. Test passes 50/50 with full CI randomization on the fixed build (eb131f01). The original sections (1-5) demonstrably fail on master d8baabb6c7e2 per issue #103120's reproducer. Sections 6-7 (max_download_threads) demonstrably fail on commit 985be25a (the broken setChanged hook). Section 8 (getSetting numeric) demonstrably failed on commit fc9a6917 (the operator Field returning String("auto") attempt).

(f) Fix is general, not a narrow patch? Yes. The audit of every SettingField* operator Field shows that SettingFieldMaxThreads is the only type currently in the tree with a non-invertible round-trip - SettingAutoWrapper already returns Field("auto") so its round-trip is invertible, and SettingFieldNumber, SettingFieldString, SettingFieldChar, SettingFieldURI, SettingFieldEnum, SettingFieldMultiEnum, SettingFieldTimezone, SettingFieldMap, SettingFieldCustom, and SettingFieldTimespan all have round-trips invertible by construction. The new resetFromDefault virtual provides a generic extension point: any future type that deliberately makes its operator Field non-invertible (per the issue's "open risks" note) can override resetFromDefault without needing changes outside its own header. The default implementation matches the legacy behaviour exactly, so existing types are unaffected.

@clickhouse-gh

clickhouse-gh Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.10% +0.10%
Functions 91.10% 91.10% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 93.75% (15/16) | lost baseline coverage: 1 line(s) · Uncovered code

Full report · Diff report

@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.

Now it's perfect.

@alexey-milovidov alexey-milovidov self-assigned this May 6, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 6, 2026
Merged via the queue into ClickHouse:master with commit 23a4573 May 6, 2026
165 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 6, 2026
Algunenano added a commit to Algunenano/ClickHouse that referenced this pull request May 7, 2026
Master added `SettingFieldBase::resetFromDefault` (issue ClickHouse#103120, PR ClickHouse#103991)
to preserve `SettingFieldMaxThreads::is_auto` across `SET <name> = DEFAULT`,
which the previous `Field` round-trip in `BaseSettings::resetValueToDefault`
dropped because `SettingFieldMaxThreads::operator Field` is non-invertible.
This branch removed `SettingFieldBase` entirely, so the override mechanism
doesn't apply.

Equivalent fix without virtuals: keep one default-constructed `Data`
instance per `Accessor` (no per-setting cost) and reset individual settings
via a per-type `typed_copy` function pointer in `SettingFieldOps` that does
`*static_cast<T *>(dst) = *static_cast<const T *>(src)`. The defaulted copy
assignment of `SettingFieldMaxThreads` preserves all members including
`is_auto`, so the regression test `04202_set_default_preserves_max_threads_auto`
passes without any per-setting code.

The cached default `Data` also lets `getDefaultValueString` read directly
through the existing `to_string` op, replacing the per-setting
`getSettingDefault_` switch and the `default_fn_` / `default_index_` fields
in `FieldInfo` (16 B × ~2k settings ≈ 32 KB removed from the `Settings`
accessor singleton).

Also rename the `sf*` short helpers in `SettingsFields.h` to spelled-out
`settingField*` names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default 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.

resetValueToDefault round-trip through Field loses SettingFieldMaxThreads::is_auto flag

4 participants