Skip to content

Fix LOGICAL_ERROR 'Trying to get name of not a column' in multiIf matcher inside table function argument - #106647

Merged
al13n321 merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-stid-2310-multi-if-asterisk-numbers
Jun 19, 2026
Merged

al13n321 merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-stid-2310-multi-if-asterisk-numbers

Conversation

@groeneai

@groeneai groeneai commented Jun 6, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #43199
Closes: #97988
Closes: #100323
Related: #106172
Related: #100436 (comment)

When a multiIf argument inside a table-function call contains a matcher (*), the new-analyzer constant-folding helper held the condition through auto & cond_node = multi_if_args[2 * pair];. resolveExpressionNode rebinds matchers in place, swapping multi_if_args[0] for an empty ListNode. A subsequent argument throwing UNKNOWN_IDENTIFIER causes resolveTableFunction to skip analysis but the original argument tree already carries the corrupted child, so toAST() emits multiIf(ExpressionList(), ...) and evaluateConstantExpression raises LOGICAL_ERROR from IAST::appendColumnName.

Snapshot cond_node into a local copy before resolving, mirroring the is_special_function_if pattern at resolveFunction.cpp:485.

Reproducer (aborts on master HEAD 378a25bb3b15, returns clean UNSUPPORTED_METHOD with the fix):

SELECT * FROM numbers(multiIf(*, number, 1), 2);

This is a tightened resubmit of #106172 with only the new-analyzer half; the old-analyzer hunk in InterpreterSelectQuery.cpp and 04303 test were dropped per the "old analyzer frozen except crashes" policy that closed #106172 on 2026-06-05.

CIDB shows 25+ unrelated PR sightings and 2 master hits in the last 30 days (BuzzHouse amd_debug 2026-06-01, AST fuzzer amd_debug 2026-05-30) under runner test name "Logical error: Trying to get name of not a column: A (STID: 2310-*)". The runner replaces format placeholders with A, B, C; the underlying message is "Trying to get name of not a column: ExpressionList".

CI report context for the directive on #100436: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100436&sha=76d70c8c3f11a42854a7f3babb04d23e58fec931&name_0=PR&name_1=AST%20fuzzer%20%28amd_tsan%29

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 "Trying to get name of not a column: ExpressionList" raised by queries that pass an asterisk inside multiIf to a table function argument, e.g. numbers(multiIf(*, ...), 2). The query now rejects the unresolvable matcher with UNSUPPORTED_METHOD.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.6.1.1016

…h matcher inside table function

Closes: ClickHouse#43199
Closes: ClickHouse#97988
Closes: ClickHouse#100323
Related: ClickHouse#106172

The new-analyzer constant-folding helper for `multiIf` in `resolveFunction.cpp`
held its condition through `auto & cond_node = multi_if_args[2 * pair];`.
`resolveExpressionNode` rebinds its argument when the node is a matcher (`*`),
which silently swapped the slot in `multi_if_args` for an empty `ListNode`.

When a later argument throws `UNKNOWN_IDENTIFIER`, `resolveTableFunction`
catches it (`QueryAnalyzer.cpp:4329-4351`) and skips analysis, but the
original argument tree already carries the corrupted `ListNode` child.
`table_function_node_typed.toAST()` re-emits `multiIf(ExpressionList(), ...)`,
`parseArguments` accepts it, and `TableFunctionNumbers::evaluateArgument`
calls `evaluateConstantExpression`, which raises a `LOGICAL_ERROR` from
`IAST::appendColumnName` (`IAST.h:122`) when walking `ASTFunction`'s children.

Snapshot `cond_node` into a local copy before `resolveExpressionNode` so
matcher rebinding cannot leak back into the original slot. Mirrors the
`is_special_function_if` pattern at `resolveFunction.cpp:485`.

Reproducer (aborts master HEAD `378a25bb3b15`, returns clean
`UNSUPPORTED_METHOD` with the fix):

  SELECT * FROM numbers(multiIf(*, number, 1), 2);

CIDB shows 25+ unrelated PR sightings and 2 master hits in the last 30 days
(BuzzHouse `amd_debug` 2026-06-01 sha `7ca836227b`, AST fuzzer `amd_debug`
2026-05-30 sha `d2e9760e19`) under runner test name
"Logical error: Trying to get name of not a column: A (STID: 2310-*)".
The "A" is a placeholder; the underlying message is
"Trying to get name of not a column: ExpressionList".

This is a tightened resubmit of ClickHouse#106172 with only the new-analyzer half;
the bundled old-analyzer hunk in `InterpreterSelectQuery.cpp` and the
`04303` test were dropped per the "old analyzer frozen except crashes"
policy that closed ClickHouse#106172 on 2026-06-05.

Reference: ClickHouse#100436 (comment)

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

groeneai commented Jun 6, 2026 •

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (per TASK.md Phase 4):

Item Status
a) Deterministic repro? YES. SELECT * FROM numbers(multiIf(*, number, 1), 2); aborts on master HEAD 378a25bb3b15 with the exact stack trace from the reports (IAST.h:122 → ASTFunction::appendColumnNameImpl → evaluateConstantExpression.cpp:106 → TableFunctionNumbers::evaluateArgument → QueryAnalyzer::resolveTableFunction). 20/20 iterations on the pre-fix debug binary aborted.
b) Root cause explained? YES. auto & cond_node = multi_if_args[2 * pair]; is a reference into the argument vector. resolveExpressionNode rebinds matchers in place by writing into the slot, so the reference silently swaps multi_if_args[0] for an empty ListNode. When a sibling argument throws UNKNOWN_IDENTIFIER, resolveTableFunction catches it (QueryAnalyzer.cpp:4329-4351) and skips analysis , but the original tree already carries the corrupted child. toAST() re-emits multiIf(ExpressionList(), ...), parseArguments accepts it, and evaluateConstantExpression(arg, ctx) calls arg->getColumnName() → walks ASTFunction children → hits the ASTExpressionList child whose default appendColumnName throws.
c) Fix matches root cause? YES. Snapshot cond_node into a local QueryTreeNodePtr before calling resolveExpressionNode. Mirrors the is_special_function_if pattern already in this file at line 485. The matcher rebinding is now contained to the local variable and cannot leak back into multi_if_args.
d) Test intent preserved? New tests added? YES. New 04323_multi_if_asterisk_table_function.sql covers (1) the longer fuzzer-derived shape with materialize(toLowCardinality(...)) and moduloOrZero returning serverError UNSUPPORTED_METHOD; (2) the minimal shape numbers(multiIf(*, number, 1), 2) returning UNSUPPORTED_METHOD; (3) the smaller-arg shape numbers(multiIf(*, 1, 2), 2) returning NUMBER_OF_ARGUMENTS_DOESNT_MATCH; (4)+(5) two positive cases proving the constant-fold fast path still selects the correct branch. Sibling tests 02374_combine_multi_if_and_count_if_opt, 03168_fuzz_multiIf_short_circuit, 00328_long_case_construction all still pass on the fix branch.
e) Both directions demonstrated? YES. Pre-fix build/programs/clickhouse (master HEAD): 20/20 abort with Logical error: 'Trying to get name of not a column: ExpressionList'. Post-fix binary (incremental rebuild from same tree, only resolveFunction.cpp changed): 20/20 raise clean UNSUPPORTED_METHOD, server stays up across all iterations, zero fatal entries in server.log.
f) Fix is general, not a narrow patch? YES. The other auto & ... = arguments[N] patterns in resolveFunction.cpp (lines 1317 and 1685) were audited under #106172 and do not pass the reference into anything that rebinds matchers , safe. The corruption is specific to the multiIf constant-fold helper because it is the only call site that resolves an argument and then continues using the same slot. The fix is the smallest possible change to make matcher rebinding harmless to the original tree.

Session: cron:clickhouse-ci-task-worker:20260606-202800

@groeneai

groeneai commented Jun 6, 2026 •

Copy link
Copy Markdown
Collaborator Author

cc @KochetovNicolai @novikd, could you review this? Tightened resubmit of #106172 with only the new-analyzer half: snapshot the multiIf condition into a local copy before resolveExpressionNode so matcher rebinding cannot corrupt the slot in multi_if_args. Old-analyzer hunk dropped per the policy that closed #106172.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4f6d3a1]

Summary: ❌

job_name test_name status info comment
BuzzHouse (amd_tsan) FAIL
ThreadSanitizer: data race (STID: 3336-2c6d) FAIL cidb, issue
Stress test (amd_msan) ERROR

AI Review

Summary

This PR fixes the new-analyzer multiIf constant-folding helper so resolving a matcher condition uses a local QueryTreeNodePtr snapshot instead of a reference into the original argument vector. The change matches the existing branch-copy pattern in the same helper, and the added stateless test covers the table-function fallback path that previously surfaced as LOGICAL_ERROR.

Final Verdict

Status: ✅ Approve

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

groeneai commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator Author

CI ledger — post-CI triage for HEAD 6ec6986a8825

CI fully finished for HEAD 6ec6986a8825. Triaged every reported failure; nothing is PR-caused.

Check Test Disposition
CH Inc sync (downstream sync bot) Infra / not part of praktika — sync PR has merge conflicts; not blocking and unrelated to this change.

All 146 praktika checks pass (Style, Fast test, Builds, Stateless tests across all sanitizers + storage variants, Integration tests across all sanitizers, Stress tests, AST fuzzer, BuzzHouse, Performance Comparison, Compatibility, Install packages, SQLLogic, Mergeable Check, Finish Workflow). CIDB returns zero FAIL/ERROR rows for this PR in the last 24h.

Ready for review.

— groeneai (cron:our-pr-ci-monitor:20260607-033000)

@clickhouse-gh

clickhouse-gh Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.50% 77.50% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 5/5 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@al13n321
al13n321 added this pull request to the merge queue Jun 19, 2026
@al13n321

Copy link
Copy Markdown
Contributor

Overrode CI.

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

5 participants