Skip to content

Replace two internal error messages for plain SQL mistakes - #116812

Merged
alexey-milovidov merged 4 commits into
masterfrom
fix-internal-error-messages-for-sql-mistakes
Aug 29, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
fix-internal-error-messages-for-sql-mistakes

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Related: #116806
Related: #116809

Two more findings from the survey of the error messages ClickHouse produces for mistakes in SQL queries (the queries of ClickBench, TPC-H, TPC-DS and the Join Order Benchmark, damaged at random). Both are rare in the corpus, but each answers an ordinary mistake with a message about ClickHouse internals rather than about the query.

Comparing a number with an empty string reported an EOF error. WHERE numeric_column <> '' is a common way to write "is not empty" for someone coming from another database, and it produced:

SELECT toInt32(1) = ''
Code: 32. DB::Exception: Attempt to read after eof: while converting '' to Int32 (ATTEMPT_TO_READ_AFTER_EOF)

convertFieldToType parses the string literal with deserializeWholeText, and a value that ends before the deserializer expected surfaces as Attempt to read after eof — which reads like a problem with the stored data, not with the query. The almost identical = 'abc' already gets a proper message, so the empty and truncated cases now get the same one:

Code: 53. DB::Exception: Cannot convert string '' to type Int32 (TYPE_MISMATCH)

A correlated subquery of several columns named a C++ method. Dropping EXISTS from NOT EXISTS (SELECT * FROM orders WHERE o_custkey = c_custkey), which is what removing a single token from TPC-H Q22 does, leaves a correlated subquery of several columns where a single value is expected:

Code: 1. DB::Exception: Method getResultType is supported only for correlated query node with 1 column,
but got 9 (UNSUPPORTED_METHOD)

getResultType is an implementation detail, and UNSUPPORTED_METHOD is not what went wrong — the query is invalid:

Code: 20. DB::Exception: A correlated subquery used as an expression must return exactly one column,
but it returns 9 (NUMBER_OF_COLUMNS_DOESNT_MATCH)

The other getResultType throw in QueryNode (for a non-correlated node) is left alone: it is an internal invariant, and the way it is reached from SQL is a separate bug (#115835).

01311_comparison_with_constant_string asserted ATTEMPT_TO_READ_AFTER_EOF for SELECT 0 = '' and is updated to TYPE_MISMATCH. The other tests that expect ATTEMPT_TO_READ_AFTER_EOF (01888_read_int_safe, 00700_to_decimal_or_something_1, 02477_invalid_reads, 03716_topk_bad_data, 03927_sumcount_compatibility) go through the conversion functions or aggregate-state deserialization rather than convertFieldToType and are unaffected — they were run and pass.

Changelog category (leave one):

  • Improvement

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

Comparing a number with an empty or truncated string literal, such as WHERE numeric_column <> '', now reports Cannot convert string '' to type Int32 instead of Attempt to read after eof. A correlated subquery returning several columns where a single value is expected now says so, instead of reporting that the getResultType method is not supported.


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

Version info

  • Merged into: 26.9.1.328 (included in 26.9 and later)

Both come from the survey of the error messages that ClickHouse produces
for damaged benchmark queries (ClickBench, TPC-H, TPC-DS, the Join Order
Benchmark). They are rare in that corpus but each of them answers an
ordinary mistake with a message about ClickHouse internals.

Comparing a numeric column with an empty string reported an EOF error:

    SELECT toInt32(1) = ''
    Code: 32. Attempt to read after eof: while converting '' to Int32

`convertFieldToType` parses the literal with `deserializeWholeText`,
which reports a value that ends before it expected as an attempt to read
after eof. That reads like a problem with the data, not with the query,
and the very similar `= 'abc'` already gets a proper message. Give the
empty and truncated cases the same one:

    Code: 53. Cannot convert string '' to type Int32

Dropping `EXISTS` from `NOT EXISTS (SELECT * FROM t WHERE t.a = o.b)` -
which is what removing one token from TPC-H Q22 does - leaves a
correlated subquery of several columns where a single value is expected,
and that was reported as

    Code: 1. Method getResultType is supported only for correlated query
    node with 1 column, but got 9

The method is an implementation detail; the user needs to know what is
wrong with the query:

    Code: 20. A correlated subquery used as an expression must return
    exactly one column, but it returns 9

`01311_comparison_with_constant_string` asserted the old error code for
`SELECT 0 = ''` and is updated. The other tests that expect
`ATTEMPT_TO_READ_AFTER_EOF` go through the conversion functions or
aggregate-state deserialization rather than `convertFieldToType`, and
still pass.
@clickhouse-gh

clickhouse-gh Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [47bf54d]

Summary: ✅


AI Review

Summary

This PR replaces two internal exceptions with query-facing diagnostics: empty or truncated string literals compared to numeric values now report TYPE_MISMATCH, and multi-column correlated subqueries used as scalar expressions now report NUMBER_OF_COLUMNS_DOESNT_MATCH. After reviewing the current PR diff, the live review discussion, and the PR-head file contents on GitHub, I did not find a correctness or coverage issue that warrants a new review comment.

Missing context / blind spots
  • ⚠️ The workspace is checked out at the synthetic merge ref pull/116812/merge, not the PR head 47bf54d65e5f1d2aef376d8787a8af6d1745c071, so I validated the touched files against GitHub-fetched PR-head contents. There is no local build artifact in this workspace, so I could not execute the new query shapes locally.
Final Verdict

✅ No new findings.

LLVM Coverage Report

Measured on commit 47bf54d.

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: 8/9 (88.89%) · Uncovered code

Full report · Diff report

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

clickhouse-gh Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 47bf54d65 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

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

Job report

The messages it asserts are produced by the analyzer; with `enable_analyzer = 0`
the same errors come from a different code path and are worded differently, so
the test failed in the `old analyzer` CI configuration.
`_cleanup_database` in `clickhouse-test` asks tests numbered from 02800 on
to leave no tables behind.
The test showed the `Date` path as a contrast to the integer one, and did
it by pinning the whole message - which couples it to
#116817, where the reason
part of `Cannot parse date` changes. Normalise the reason away: what this
test is about is that the `Date` path has a message of its own, not what
that message says.

@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.

Very good.

@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 d63d800 Aug 29, 2026
174 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-internal-error-messages-for-sql-mistakes branch August 29, 2026 12:50
@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