Repository navigation
Fix a logical error when a setting holding a disk(...) value is assigned twice - #118993
Conversation
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.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 rounds; 1 finding, resolved).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260909-100200 |
|
Workflow [PR], commit [705e28e] Summary: ✅
AI ReviewSummaryThis PR fixes the Final Verdict✅ No new blocking or major issues found in the current PR head. LLVM Coverage ReportMeasured on commit 705e28e.
Changed lines: Changed C/C++ lines covered: 3/8 (37.50%) · Uncovered code |
|
cc @george-larionov @pufit, could you review this? |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units12 translation units recompiled, 26 s compile time in total, 12 of them have a recent master baseline. |
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.Results:
Backport the fix to CC component owner: @alexey-milovidov @Algunenano Analysis metadata
Introducing change: not identified
|
|
Confirmed on all four active release branches, and a single label covers them. Measured with the branch-head builds from
Controls: the first The label to use is One arm the backport will not close: over the native protocol the second @alexey-milovidov could you apply |
Backport #118993 to 26.8: Fix a logical error when a setting holding a `disk(...)` value is assigned twice
Backport #118993 to 26.3: Fix a logical error when a setting holding a `disk(...)` value is assigned twice
Changelog category (leave one):
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 aSETof a custom setting that already held an AST value such asdisk(type = 's3', ...). Assigning such a setting a second time in one session, or clamping a nestedSETTINGSclause against it, reached a comparison that was never implemented.FieldFromASTImplnow 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 raisedLOGICAL_ERROR: Method == not implemented for AST. Two requests against a server with the shipped configuration are enough:On a release build the second statement returns
Code: 49instead of aborting, since aLOGICAL_ERRORaborts only in debug and sanitizer builds. It is also reachable through a nestedSETTINGS SQL_x = disk(...)clause, clamped against the session value (QueryTreeBuilder->SettingsConstraints::clamp).Root cause.
Field::operator==short-circuits on the type tag and dispatches toCustomType::operator==only when both operands areCustomType. An AST-valued setting is a designed, long-lived value in the custom-settings map ofSettings, so a second AST assignment supplies that pair, and the unchanged-value test atSettingsConstraints.cpp:362asserted instead of answering.Change.
FieldFromASTImpl::operator ==type-checks its operand and compares the unmasked formatted value. This mirrorsAggregateFunctionStateData::operator==and agrees withFieldVisitorHash, which already defines aCustomType'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 byStress 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 aCustomTypeconstraint bound, which no input produces:ParserSettingsProfileElementaccepts onlyParserLiteral, and the configuration route ends inField::restoreFromDump, which cannot restore aCustomType.Behaviour change: on the clamping path an identical AST value re-assigned is now recognised as unchanged and dropped, where it previously aborted. The
SETpath is unaffected.Workflow [PR]
Sync PR [sync-upstream/pr/118993]
Version info
26.8.44.3,26.3.69.5