Skip to content

Backport #119317 to 26.7: Fix a crash and a LOGICAL_ERROR when trim(BOTH '' FROM x) is used where a function is expected - #119856

Merged
clickhouse-gh[bot] merged 2 commits into
26.7from
backport/26.7/119317
Sep 14, 2026
Merged

clickhouse-gh[bot] merged 2 commits into
26.7from
backport/26.7/119317

Conversation

@robot-ch-test-poll4

@robot-ch-test-poll4 robot-ch-test-poll4 commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #119317

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.7.8.15

…BOTH '' FROM x)` is used where a function is expected
@robot-ch-test-poll4 robot-ch-test-poll4 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix labels Sep 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [6808d57]

Summary: ✅

@groeneai

Copy link
Copy Markdown
Collaborator

05175_trim_empty_chars_is_a_function_call cannot pass on 26.7: it asserts two behaviours this branch predates

The cherry-picked fix itself is complete here: this PR's file list and per-file counts are
byte-identical to the master merge commit of #119317, the pre-image the parser change removes applied
cleanly, and 02864_statistics_ddl (which the same PR extended with the
STATISTICS(trim(BOTH '' FROM 'x')) case that produced the original Bad cast from DB::ASTLiteral to DB::ASTFunction) is green here. Only the new test file is unportable, in exactly two statements:

  1. .sql:19 ALTER TABLE t_alter MODIFY COLUMN c Int64 STATISTICS(trim(BOTH '' FROM 'x')) succeeds
    instead of raising INCORRECT_QUERY. Applying a column-level STATISTICS clause in
    ALTER ... ADD/MODIFY COLUMN arrived with c8f3a4781ae2ef4e995ade921810e00bdedb47f4; before it the
    clause is silently dropped, so no type validation runs and there is nothing to assert.
  2. .sql:47 CREATE TABLE ok (c Int64 STATISTICS(tdigest) CODEC(ZSTD(3)), ...) fails with
    Syntax error: failed at position 99 (CODEC). The order-agnostic column-modifier loop arrived with
    0208555a59626ca66364e1326e992b97b017d340; here the modifiers still have to be written in one fixed
    order, COMMENT, CODEC, STATISTICS, TTL, PRIMARY KEY, SETTINGS.

Both commits belong to #112788, merged to master on 2026-08-14, after the 26.7 branch cut and before
the 26.8 one: 26.8 has both, 26.3/26.6/26.7 have neither. That line also names statistics types that
are not registered everywhere, uniq_v2 on neither 26.3 nor 26.6 and basic not on 26.3, so fixing
the order alone still leaves it failing on the two older branches. The 26.8 arm is the control: the
one active branch with #112788, green on this test and already merged, while the other three fail it
deterministically.

Smallest edit that works identically on 26.3, 26.6 and 26.7, if the test is worth keeping there:

  • delete .sql:19 and .reference:22; line 18, ALTER TABLE t_alter ADD STATISTICS c TYPE trim(BOTH '' FROM 'x'), keeps the ALTER slot covered and passes here;
  • rewrite .sql:47 as CREATE TABLE ok (c Int64 CODEC(ZSTD(3)) STATISTICS(tdigest), d Int64 CODEC(NONE) STATISTICS(uniq, minmax), INDEX i c TYPE minmax) ENGINE = MergeTree ORDER BY c SETTINGS auto_statistics_types = 'tdigest, uniq';, put that same setting text in the fourth position(...)
    of .sql:48, and mirror both lines into .reference:64-65. Expected values stay 1 1 1 1 and the
    other three position(...) arguments stay as they are, since ASTColumnDeclaration::formatImpl here
    already prints CODEC before STATISTICS; tdigest, uniq and minmax are registered on all
    four branches.

If carrying the test here is not worth it, dropping the 05175 pair from this branch still leaves the
02864 case asserting the fix on it. Importing #112788 first, or declining this arm, are the other
two options, and those are yours rather than mine.

I hold triage only on this repository and maintainerCanModify is false on this head, so I cannot
apply the edit myself.

…ammar

Two statements of the new test assert behaviours that arrived in master with #112788, after the 26.7 branch cut:

- `ALTER TABLE ... MODIFY COLUMN c Int64 STATISTICS(...)` silently drops the column-level `STATISTICS` clause here, so no type validation runs and the expected `INCORRECT_QUERY` is never thrown. The statement is removed; the `ALTER TABLE ... ADD STATISTICS` line keeps the `ALTER` slot covered.
- Column modifiers must be written in the fixed order `COMMENT`, `CODEC`, `STATISTICS`, `TTL` on this branch, so `STATISTICS(tdigest) CODEC(ZSTD(3))` is a syntax error. The `CREATE TABLE ok` line is rewritten with `CODEC` before `STATISTICS`; `ASTColumnDeclaration` already formats it in that order, so the expected output is unchanged.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=119856&sha=03e5c7fd77e86da6abee8ab725a382bd0ffb4cd3&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29
PR: #119856

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thanks, the diagnosis is right: both statements assert behaviours that came with #112788, which 26.7 predates. Applied the smallest edit in 6808d57: dropped the ALTER TABLE ... MODIFY COLUMN ... STATISTICS(...) statement (and its reference line), and rewrote the CREATE TABLE ok line with CODEC before STATISTICS. The auto_statistics_types = 'basic, uniq_v2' text stays as is, since 26.7 registers both basic and uniq_v2. The reordered line was checked on a fixed-order-grammar binary: it parses and ASTColumnDeclaration formats CODEC before STATISTICS, so the reference is unchanged there.

@clickhouse-gh
clickhouse-gh Bot merged commit 5cf8a36 into 26.7 Sep 14, 2026
38 of 39 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport/26.7/119317 branch September 14, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants