Repository navigation
Scope parser error messages to the current statement - #105480
alexey-milovidov merged 5 commits into
Conversation
Three error paths in `tryParseQuery` (lookahead lexical error, post-parse lexical error, unmatched parentheses) passed `all_queries_end` to the error formatter instead of the end of the current statement. Under `clickhouse-local --ignore-error` over a multi-statement input, each error included every subsequent statement, producing O(N^2) output for N malformed statements. Compute the current statement end via a fresh iterator walk from the start of the token stream. Clamp to `last_token.end` to keep `writeQueryAroundTheError` from underflowing `size_t` when parser backtracking pushes the highlighted token past the next `;` (the failure mode that killed PR ClickHouse#101708 in `Fast test`). Closes ClickHouse#101509.
|
Pre-PR validation gate (session: cron:clickhouse-ci-task-worker:20260520-230000) a) Deterministic repro? Yes. b) Root cause explained? Yes. Three error paths in c) Fix matches root cause? Yes. Each of the three sites now passes d) Test intent preserved / new tests added? New test e) Demonstrated in both directions? Yes. Built without the patch: f) Fix is general? Yes. Same helper ( |
|
cc @evillique @alexey-milovidov @george-larionov: could you review? This is a follow-up to PR #93876 (which scoped only the generic syntax-error path) and supersedes the closed PR #101708. The clamp in the |
|
Workflow [PR], commit [1b595ba] Summary: ✅
AI ReviewSummaryThis PR scopes the SQL parser's lexical-error and unmatched-parentheses diagnostics to the current statement for multi-statement input, and adds focused stateless coverage for the affected paths, including the Final VerdictStatus: ✅ Approve |
The lambda walked tokens looking for `Semicolon` or `EndOfStream`, but once the lexer is past `max_query_size`, `Lexer::nextToken` forces type `ErrorMaxQuerySizeExceeded` on every call - including the natural `EndOfStream`. The loop only checked `isEnd()`, so it never terminated: each `++iter` pushed another zero-width error into `Tokens::data` and the process appeared hung. Surfaced as "Server died" in `Fast test` for test `03328_syntax_error_exception`, which sends `SELECT '<long string>'` with `max_query_size=20`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105480&sha=04a68f7fb9f730b55151fe49b994bd0eb875f396&name_0=PR&name_1=Fast%20test Fix: stop the lambda on `ErrorMaxQuerySizeExceeded` too. Other lexer error types (`Error`, `ErrorWrongNumber`, the unclosed-quote variants) are recoverable - the lexer's `pos` keeps advancing past them and eventually returns `EndOfStream` - so we still walk through them to reach the real statement boundary. Confirmed locally that test `03328_syntax_error_exception` case 3 (`SELECT ыыы'`) still reports `: ыыы'` in the error message. Also extended the regression test `04262_no_excessive_output_on_lexical_error` with a `max-query-size` path that exercises the hang directly: pre-fix the shell call would not return within the test timeout, post-fix it returns one error message immediately. Verified with 20x `--test-runs` of both `03328_syntax_error_exception` and `04262_no_excessive_output_on_lexical_error`: 40/40 pass.
Fast test fix pushed (
|
Fixes Build (arm_tidy) readability-use-std-min-max error introduced in commit b302a7f.
|
Pushed follow-up commit 8148731 to fix the Build (arm_tidy) failure on b302a7f. clang-tidy 21 flagged the new Awaiting CI re-run. (session cron:clickhouse-ci-task-worker:20260521-181500) |
This comment was marked as outdated.
This comment was marked as outdated.
CI ledger — covered SHA:
|
| Check | Test | Disposition |
|---|---|---|
Stateless tests (amd_tsan, parallel, 1/2) |
00096_obfuscator_save_load, 00175_obfuscator_schema_inference |
flaky chronic trunk — tasks 2026-06-02-ci-00096obfuscatorsaveload-chronic-f / 2026-06-02-ci-00175obfuscatorschemainference-ab |
Unit tests (asan_ubsan) |
(check-level) | infra/chronic UBSan UntrackedMemoryCounter — task 2026-06-03-ci-p1-chronic-ubsan-in-untrackedmemoryc |
Unit tests (asan_ubsan, function_prop_fuzzer) |
FunctionsStress.stress, AllTests |
follows the asan_ubsan check-level fail above (same UntrackedMemoryCounter teardown). |
Unit tests (msan, function_prop_fuzzer) |
FunctionsStress |
infra/chronic msan-side counterpart of the same family. |
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) |
03100_lwu_07_merge_patches |
chronic flaky lightweight-updates merge-patches s3 test — unrelated to this parser-error-message scoping fix. |
No PR-caused correctness failures. Awaiting human review.
Session: cron:our-pr-ci-monitor:20260604-213000
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 31/31 (100.00%) | Lost baseline coverage: none · Uncovered code |
CI finish ledger — 1b595baCI has fully finished (Finish Workflow + Mergeable Check passed; all test checks green on this master-merge head). Every red check has an owner below; only
No functional/integration/stress/fuzzer/sanitizer/unit test failed on this head — the prior chronic flakies (AST fuzzer STID 1288-3bd5, obfuscator) did not recur after the master merge. Addresses issue #101509. Ready for review. Session id: cron:our-pr-ci-monitor:20260625-170000 |
…r-excessive-output-101509 Scope parser error messages to the current statement
Fixes #101509.
Three error paths in
tryParseQuery(lookahead lexical error, post-parse lexical error, unmatched parentheses) passedall_queries_endto the error formatter instead of the end of the current statement. Underclickhouse-local --ignore-errorover a multi-statement input, each error included every subsequent statement, producing O(N^2) output for N malformed statements.The fix walks a fresh iterator from the start of the token stream to the next
;(or end of input) and uses that as the error-message end. The result is clamped to at leastlast_token.endto keepwriteQueryAroundTheErrorfrom underflowingsize_twhen parser backtracking pushes the highlighted token past the next semicolon. That underflow is the failure mode that killed the earlier attempt in PR #101708 as "Server died" inFast test.For the unmatched-parens path the reported paren list is also filtered to parens that fall inside the current statement, so the highlight loop's
assert(current_position_to_hilite <= end)inwriteQueryWithHighlightedErrorPositionscannot fire on parens belonging to later statements.Regression test
04262_no_excessive_output_on_lexical_error.shexercises all three paths: 10 identical bad statements produce 10 error mentions of the offending text (not 10 + 9 + ... + 1 = 55). A sanity case ensures 10 valid statements produce 0 error lines.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an issue where running multiple statements in
clickhouse-local --ignore-errorwould echo every subsequent statement inside the error message for each lexical error or unmatched-parenthesis error.Version info
26.7.1.128