Skip to content

Put the actionable part of analyzer error messages first - #116809

Merged
alexey-milovidov merged 5 commits into
masterfrom
improve-analyzer-error-messages
Aug 29, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
improve-analyzer-error-messages

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

Related: #116806

Continues the survey of the error messages that ClickHouse produces for mistakes in SQL queries: the queries of ClickBench, TPC-H, TPC-DS and the Join Order Benchmark were damaged at random (dropping a token, a bracket or a comma, changing, dropping, inserting or transposing a single letter, swapping or duplicating a token, truncating the query), which gave 8340 queries and 7752 errors. 2471 of them carry a Maybe you meant hint, and 85% of the UNKNOWN_IDENTIFIER errors do - the typo correction works well.

The hint was printed after the whole query. It is the part of the message that says what to do about the mistake, and the formatted query goes into the message in full, so in the median a user had to read 523 characters before reaching it, in 22% of the cases more than a thousand, and at worst 6588 - several screens of a terminal for a query of the size TPC-DS queries have:

Code: 47. DB::Exception: Unknown expression or function identifier `w_warehoufe_sq_ft` in scope SELECT
w_warehouse_name, w_warehouse_sq_ft, w_city, ... 6 kilobytes of query ... LIMIT 100. Maybe you meant:
['w_warehouse_sq_ft']. (UNKNOWN_IDENTIFIER)

Moving the hint in front of the query drops the median distance to it from 523 to 81 characters and the maximum from 6588 to 162:

Code: 47. DB::Exception: Unknown expression identifier `w_warehoufe_sq_ft`. Maybe you meant:
['w_warehouse_sq_ft']. In scope SELECT w_warehouse_name, ... (UNKNOWN_IDENTIFIER)

This applies to the unknown-identifier, unknown-column-of-a-table-expression, nested-path, unknown-function, unknown-aggregate-function and unknown-table messages. in scope became . In scope so that the messages read as sentences.

A comma missing in the FROM clause produced a misleading message. In

SELECT item.i_brand_id FROM date_dim AS dt, store_sales item WHERE dt.d_date_sk = 1

item silently becomes an alias of store_sales, and the reference to item.i_brand_id was reported as

Identifier 'item.i_brand_id' cannot be resolved from table with name item

while a table named item does exist and does have an i_brand_id column. The message named the alias without ever saying that it is one, so it looked like the server had lost the column. It now names the table the alias stands for, which is what makes the missing comma visible:

Identifier 'item.i_brand_id' cannot be resolved from table with name item (an alias of store_sales)

03096_text_log_format_string_args_not_empty is updated for the new message_format_string values. Validated by running the 121 stateless tests that mention any of these messages; the only failures are unrelated environment ones (no ZooKeeper, no writeable access storage, no test clusters, no system log tables in the local setup), and every hint-sensitive test passes.

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The Maybe you meant hint in the error messages for an unknown column, function or table is now printed before the query instead of after it, so it is no longer behind kilobytes of text for a large query. When a column cannot be resolved from a table expression that has an alias, the message now also names the table the alias refers to, which makes a comma missing between two table names in the FROM clause visible.


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

Continues the survey of the error messages that ClickHouse produces for
damaged benchmark queries (ClickBench, TPC-H, TPC-DS, the Join Order
Benchmark): 8340 mutated queries, 7752 errors, of which 2471 carry a
`Maybe you meant` hint.

That hint is the part of the message that says what to do about the
mistake, and it was printed after the whole formatted query. The query
goes into the message in full, so in the median the user had to read 523
characters to reach the hint, in 22% of the cases more than a thousand,
and at worst 6588 - several screens of a terminal for a query of the size
that TPC-DS queries have. Move it in front of the query: the median drops
to 81 characters and the maximum to 162.

The same corpus also shows that a comma missing between two table names
in the FROM clause produces a genuinely misleading message. In

    FROM date_dim AS dt, store_sales item

`item` silently becomes an alias of `store_sales`, and a reference to
`item.i_brand_id` was reported as

    Identifier 'item.i_brand_id' cannot be resolved from table with name item

while a table named `item` does exist and does have that column - the
message named the alias and never mentioned that it is one. Name the
table the alias stands for:

    ... cannot be resolved from table with name item (an alias of store_sales)
@clickhouse-gh

clickhouse-gh Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2449613]

Summary: ✅


AI Review

Summary

This PR moves analyzer typo hints ahead of the formatted query and adds alias context for unresolved identifiers from table expressions. The earlier materialized-CTE leak is fixed, but one UNKNOWN_IDENTIFIER path still leaves the actionable FROM-clause guidance after In scope, so the stated "actionable part first" contract is still incomplete.

Missing context / blind spots
  • ⚠️ The PR's published CI artifacts currently expose only the Build profile diff report, so I could not cross-check a full CI run from the PR itself.
Findings

⚠️ Majors
[src/Analyzer/Resolve/QueryAnalyzer.cpp:3440] The missing-FROM note is still appended via addMessage, which puts it after the full In scope ... query text. Queries such as SELECT x therefore still make the user read the formatted query before reaching the actual fix hint, even though this PR otherwise moves actionable guidance in front. Suggested fix: build from_clause_hint into the same placeholder that now carries Maybe you meant, and extend tests/queries/0_stateless/04260_hint_missing_from_clause.sh to assert the ordering as well as the presence of the note.

Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit 2449613.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 80.70% 80.80% +0.10%

Changed lines: Changed C/C++ lines covered: 55/67 (82.09%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 244961317 with master 617af45cc (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
Binary Master PR Δ
programs/clickhouse-stripped 710.07 MiB 707.02 MiB -3.06 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

`test_hive_partitioning_without_setting` in `test_storage_hdfs` and
`test_storage_azure_blob_storage` matched `Unknown expression identifier
`.*` in scope`, which the new `. In scope` wording no longer satisfies.
The pattern is relaxed to not depend on the punctuation between the
identifier and the query, so that a hint appearing between them does not
break it either.

`05046_analyzer_error_message_hint_before_the_query` asserts messages
that only the analyzer produces - with `enable_analyzer = 0` the same
errors come from `TreeRewriter` and are worded differently - so it is
tagged `no-old-analyzer`.
`_cleanup_database` in `clickhouse-test` asks tests numbered from 02800 on
to leave no tables behind.
Review pointed out that a materialized CTE is a table node over a
temporary table whose name is generated, so `table_name` there is
`_materialized_cte_<name>_<rng>` and the new note would have printed

    a (an alias of _materialized_cte_cte_1234...)

for `WITH cte AS MATERIALIZED (...) SELECT a.no_such FROM cte AS a` -
leaking an internal name where the point of the note is to show the user
something they recognise. Use `getMaterializedCTE()->cte_name`, the same
visible name the qualifier handling in this file already uses, and cover
it in the test.
@@ -3440,15 +3440,17 @@ ProjectionNames QueryAnalyzer::resolveExpressionNode(
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contract in this hunk is "put the actionable part first", but the missing-FROM guidance still goes through addMessage below, which appends it after the full In scope ... query text. For SELECT x the user still gets ... In scope SELECT x: Note: the query does not have the FROM clause..., so this class of actionable hint remains buried behind the formatted query. Please fold from_clause_hint into the same placeholder you already moved ahead of In scope, and extend 04260_hint_missing_from_clause.sh to assert the ordering rather than only the presence of the note.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done later.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good for me.

@alexey-milovidov alexey-milovidov self-assigned this Aug 29, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 29, 2026
Merged via the queue into master with commit b2fc55f Aug 29, 2026
174 checks passed
@alexey-milovidov
alexey-milovidov deleted the improve-analyzer-error-messages branch August 29, 2026 12:55
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements 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.

2 participants