Skip to content

Fix a logical error when a setting holding a disk(...) value is assigned twice - #118993

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fieldfromast-equality-for-ast-valued-settings
Sep 12, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fieldfromast-equality-for-ast-valued-settings

Conversation

@groeneai

@groeneai groeneai commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

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):

Fixed a logical error (Method == not implemented for AST) raised by a SET of a custom setting that already held an AST value such as disk(type = 's3', ...). Assigning such a setting a second time in one session, or clamping a nested SETTINGS clause against it, reached a comparison that was never implemented. FieldFromASTImpl now implements equality over the formatted value.

Description

What breaks. A custom setting (custom_settings_prefixes, SQL_ by default) may hold an AST rather than a literal. Assigning it twice in one session raised LOGICAL_ERROR: Method == not implemented for AST. Two requests against a server with the shipped configuration are enough:

SET SQL_x = disk(type = 'local', path = '/tmp/a');
SET SQL_x = disk(type = 'local', path = '/tmp/b');

On a release build the second statement returns Code: 49 instead of aborting, since a LOGICAL_ERROR aborts only in debug and sanitizer builds. It is also reachable through a nested SETTINGS SQL_x = disk(...) clause, clamped against the session value (QueryTreeBuilder -> SettingsConstraints::clamp).

Root cause. Field::operator== short-circuits on the type tag and dispatches to CustomType::operator== only when both operands are CustomType. An AST-valued setting is a designed, long-lived value in the custom-settings map of Settings, so a second AST assignment supplies that pair, and the unchanged-value test at SettingsConstraints.cpp:362 asserted instead of answering.

Change. FieldFromASTImpl::operator == type-checks its operand and compares the unmasked formatted value. This mirrors AggregateFunctionStateData::operator== and agrees with FieldVisitorHash, which already defines a CustomType's identity as its type name plus the unmasked text.

Validation. New test 05153_reassign_ast_valued_custom_setting: the server aborts on it without this change; it passes 50/50 with randomized settings. Found by Stress test (arm_release) on #113565, a bystander (report). No matching open issue.

Residual. <, <=, > and >= still assert, since no caller needs an order over an AST. Reaching one needs a CustomType constraint bound, which no input produces: ParserSettingsProfileElement accepts only ParserLiteral, and the configuration route ends in Field::restoreFromDump, which cannot restore a CustomType.

Behaviour change: on the clamping path an identical AST value re-assigned is now recognised as unchanged and dropped, where it previously aborted. The SET path is unaffected.


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

Version info

  • Backported to: 26.8.44.3, 26.3.69.5

A custom setting (custom_settings_prefixes; the shipped
programs/server/config.xml registers the SQL_ prefix) can hold an AST rather
than a literal, e.g. `SET SQL_x = disk(type = 's3', ...)`. Assigning such a
setting a second time in one session aborted the server with
`LOGICAL_ERROR: Method == not implemented for AST`.

FieldFromASTImpl is the only CustomType::CustomTypeImpl in the tree and
implemented none of the five comparison operators. Field::operator==
short-circuits on the type tag and dispatches to CustomType::operator== only
when both operands are CustomType. An AST-valued setting is a designed, long-lived
value in the custom-settings map of Settings, so a second AST assignment
supplies exactly that pair, and the unchanged-value test in getNewValueToCheck
(src/Access/SettingsConstraints.cpp:362) asserted instead of answering. The
same assertion is reachable through SettingsConstraints::clamp from a nested
SETTINGS clause (src/Analyzer/QueryTreeBuilder.cpp:317).

Implement operator== on the type that owes it rather than guarding the
comparison sites, which would leave the assertion reachable from the other ten
places that compare stored setting values. The shape follows
AggregateFunctionStateData::operator== in src/Core/Field.cpp: the four ordering
operators keep throwing, since no caller needs an order over an AST, while
equality type-checks its operand and then compares the payload. Identity is the
type name plus the unmasked text, which is what
FieldVisitorHash::operator()(const CustomType &) already uses, so equality and
hashing agree.

The comparison passes show_secrets = true because masking rewrites every
credential to [HIDDEN]. With the masked form two values differing only in a
credential compare equal, and on the clamping path a change judged equal is
erased, so a real change would be dropped. The regression test pins this
through readonly mode: an unchanged assignment returns before the constraint
check, so an exact repeat is accepted while a credential-only change is
refused.

Behaviour change: on the clamping path an identical AST value re-assigned is now
recognised as unchanged and erased, where it previously aborted. The SET path is
unaffected, since InterpreterSetQuery passes std::as_const(changes) and nothing
is erased.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Sep 9, 2026
@groeneai

groeneai commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 rounds; 1 finding, resolved).

# Sev Finding Verdict Evidence / action
1 ⚠️ The regression test could pass with an operator == that always returned false, or that compared the masked text, so it did not prove the equality semantics the changelog promises AGREE, fixed @ 705e28e7 Under readonly = 1 an assignment judged unchanged returns before the readonly check, so the verdict itself is observable. The test now pins both rows: an exact repeat is accepted, a change differing only in a credential is refused. All four mutants of the new operator redden, where two were green before
2 💡 The test's comment cites an absolute line number in SettingsConstraints.cpp, which will rot AGREE Noted, not blocking
3 💡 The body's "Validation" understates the test, which also pins the unmasked comparison AGREE Noted here rather than in the body, which is at its length budget

Severity: ❌ blocker / ⚠️ major / 💡 nit. Round 2 returned 0 findings.

Session id: cron:clickhouse-review-slot-9:20260909-100200

@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [705e28e]

Summary: ✅


AI Review

Summary

This PR fixes the LOGICAL_ERROR raised when a custom setting stores an AST-backed value and a later SET or nested SETTINGS clause compares it against another AST-backed value. I reviewed the current PR head, the prior discussion, and the touched comparison and settings paths; the new equality implementation is consistent with the existing hashing identity, and the added stateless test covers the regression cases that mattered here.

Final Verdict

✅ No new blocking or major issues found in the current PR head.

LLVM Coverage Report

Measured on commit 705e28e.

Metric Baseline Current Δ
Lines 88.90% 88.90% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 3/8 (37.50%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 9, 2026
@groeneai

groeneai commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

cc @george-larionov @pufit, could you review this? FieldFromASTImpl implemented none of the five Field comparison operators, so the unchanged-value test in SettingsConstraints::getNewValueToCheck raised Method == not implemented for AST whenever a custom setting already holding a disk(...) value was assigned again. This implements equality on that type with the same identity FieldVisitorHash already uses, the type name plus the unmasked text.

@clickhouse-gh clickhouse-gh Bot added the comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). label Sep 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 705e28e79 with master a305752bf (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

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

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

Job report

@alexey-milovidov alexey-milovidov self-assigned this Sep 12, 2026

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

Ok.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 12, 2026
Merged via the queue into ClickHouse:master with commit d5a23b5 Sep 12, 2026
174 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 Sep 12, 2026
@clickgapai

Copy link
Copy Markdown
Contributor
Reproducer
# server started with the shipped config (custom_settings_prefixes = SQL_); needs an HTTP session
curl -sS 'http://localhost:8123/?session_id=s1' --data-binary "SET SQL_x = disk(type = 'local', path = '/tmp/a')"
curl -sS 'http://localhost:8123/?session_id=s1' --data-binary "SET SQL_x = disk(type = 'local', path = '/tmp/b')"
# Code: 49. DB::Exception: Method == not implemented for AST. (LOGICAL_ERROR)

# same error via a nested SETTINGS clause clamped against the session value:
curl -sS 'http://localhost:8123/?session_id=s1' --data-binary "SELECT * FROM (SELECT 1 SETTINGS SQL_x = disk(type = 'local', path = '/tmp/c'))"

# over the native protocol the second SET fails earlier and differently
# (Code: 536 CANNOT_RESTORE_FROM_FIELD_DUMP), so use an HTTP session.

▶ Run on ClickHouse Fiddle

Results:

  • Reproduces on: 26.8, 26.7, 26.6, 26.3
  • Does not reproduce on: master
  • Tested versions: master, 26.8, 26.7, 26.6, 26.3
  • Also tested (unsupported, context only): 26.2 reproduces
  • ✓ Fix is on master — this PR's change fixes the bug on master. The releases listed above still have the bug and need the backport.

Backport the fix to 26.8, 26.7, 26.6, 26.3.

CC component owner: @alexey-milovidov @Algunenano

Analysis metadata

comp-settings · Severity P2 · Finding phase_d_pr118993

  • Verified against master build 044e813459c6 (aarch64)
Introducing change: not identified
  • No clean release baseline found and no lower bound established — source-build bisect is required to pin the introducing PR (not yet performed).
  • Walked 6 release(s) below the supported window: still reproduces down to 25.8.
  • Secondary components: comp-testing

@groeneai

Copy link
Copy Markdown
Collaborator Author

Confirmed on all four active release branches, and a single label covers them.

Measured with the branch-head builds from builds.clickhouse.com (amd64) and the reproducer above over an HTTP session, against a minimal config whose only relevant knob is the custom_settings_prefixes value the shipped programs/server/config.xml already sets (SQL_), so no unusual setup is involved:

ref build second SET, different value identical repeat nested SETTINGS clause
master 26.9.1.1382 accepted accepted accepted
26.8 26.8.3.104 Code: 49 ... Method == not implemented for AST same same
26.7 26.7.7.93 same same same
26.6 26.6.5.120 same same same
26.3 26.3.33.69 same same same

Controls: the first SET succeeds on every ref and its value is readable in system.settings, so the path is armed and only the comparison fails; on master the second value really wins (with an unmasked name, aaa2 present and aaa1 gone), so the new operator == runs rather than being skipped; and d5a23b55 is an ancestor of the master build and of none of the four, each of which still carries throwNotImplemented("==") in src/Parsers/FieldFromAST.h.

The label to use is v26.3-must-backport. Run against the active set [26.3, 26.6, 26.7, 26.8] (the head refs of the open release pull requests), tests/ci/cherry_pick_branches.py::select_backport_branches expands that one label to all four, while v26.6-must-backport would drop 26.3 and v26.8-must-backport would drop three. Both touched sources are byte-identical on all four branches and at this pull request's base (FieldFromAST.cpp 4f86b56e, FieldFromAST.h a69c086a), and the added test uses only shell_config.sh variables that exist on 26.3, so the cherry-picks should need no resolution.

One arm the backport will not close: over the native protocol the second SET fails with Code: 536 ... Couldn't restore Field from dump on master too, so that is a separate defect, and it is the one #119687 targets.

@alexey-milovidov could you apply v26.3-must-backport here?

@alexey-milovidov alexey-milovidov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 22, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 22, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 22, 2026
Backport #118993 to 26.8: Fix a logical error when a setting holding a `disk(...)` value is assigned twice
alexey-milovidov added a commit that referenced this pull request Nov 22, 2026
Backport #118993 to 26.3: Fix a logical error when a setting holding a `disk(...)` value is assigned twice
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 comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

6 participants