Repository navigation
Put the actionable part of analyzer error messages first - #116809
Conversation
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)
|
Workflow [PR], commit [2449613] Summary: ✅
AI ReviewSummaryThis 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 Missing context / blind spots
Findings
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit 2449613.
Changed lines: Changed C/C++ lines covered: 55/67 (82.09%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 units9 translation units recompiled, 34 s compile time in total, 9 of them have a recent master baseline. |
`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( | |||
| } | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This can be done later.
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 meanthint, and 85% of theUNKNOWN_IDENTIFIERerrors 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:
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:
This applies to the unknown-identifier, unknown-column-of-a-table-expression, nested-path, unknown-function, unknown-aggregate-function and unknown-table messages.
in scopebecame. In scopeso that the messages read as sentences.A comma missing in the FROM clause produced a misleading message. In
itemsilently becomes an alias ofstore_sales, and the reference toitem.i_brand_idwas reported aswhile a table named
itemdoes exist and does have ani_brand_idcolumn. 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:03096_text_log_format_string_args_not_emptyis updated for the newmessage_format_stringvalues. 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):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
Maybe you meanthint 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 theFROMclause visible.Workflow [PR]
Sync PR [sync-upstream/pr/116809]