Skip to content

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

Merged
PedroTadim merged 2 commits into
26.3from
backport/26.3/119317
Sep 14, 2026
Merged

PedroTadim merged 2 commits into
26.3from
backport/26.3/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.3.33.74

…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 [6569081]

Summary: ✅

@groeneai

Copy link
Copy Markdown
Collaborator

05175_trim_empty_chars_is_a_function_call cannot pass on 26.3: 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

The test was written against master and relied on two things that 26.3 does
not have: order-agnostic column modifiers (26.3 requires `CODEC` before
`STATISTICS`, so `STATISTICS(tdigest) CODEC(ZSTD(3))` is a syntax error) and
the `basic` / `uniq_v2` statistics types (26.3 knows only `tdigest`, `uniq`,
`countmin` and `minmax`). Column-level `STATISTICS` inside
`ALTER TABLE ... MODIFY COLUMN` is also silently dropped on 26.3, so the
`INCORRECT_QUERY` it asserted there never fires; that line is removed, as in the
26.7 backport.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=119854&sha=3de2c5540d544572f905faf598d894b7bfb95502&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan%2C%20distributed%20plan%2C%20parallel%2C%201%2F2%29
PR: #119854

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

Copy link
Copy Markdown
Member

🕵 Applied the adaptation you described in 6569081: dropped the ALTER TABLE t_alter MODIFY COLUMN ... STATISTICS(...) line (26.3 silently drops column-level STATISTICS in MODIFY COLUMN), reordered CODEC before STATISTICS in CREATE TABLE ok, and replaced 'basic, uniq_v2' with 'tdigest, uniq' in auto_statistics_types. Verified against a 26.3 binary that the old spelling is a syntax error, basic is rejected with INCORRECT_QUERY, and the new CREATE TABLE ok yields 1 1 1 1. Thanks for the precise diagnosis.

@PedroTadim
PedroTadim merged commit eae135c into 26.3 Sep 14, 2026
34 checks passed
@PedroTadim
PedroTadim deleted the backport/26.3/119317 branch September 14, 2026 07:29
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