Skip to content

Do not record handled Values parse exceptions in system error tables - #111141

Merged
pamarcos merged 12 commits into
masterfrom
values-suppress-system-errors-minimal
Jul 23, 2026
Merged

pamarcos merged 12 commits into
masterfrom
values-suppress-system-errors-minimal

Conversation

@pamarcos

@pamarcos pamarcos commented Jul 20, 2026 •

Copy link
Copy Markdown
Member

The Values streaming parser intentionally catches parse exceptions and falls back to SQL
expression parsing. Those handled exceptions were still recorded in system.errors and
system.error_log, so a successful asynchronous insert could attribute errors to its
AsyncInsertFlush query.

Add Exception::SuppressErrorCodesScope as a reusable thread-local RAII mechanism for code paths
that intentionally construct and handle exceptions without increasing the system error counters.
It can be used anywhere an expected or speculative failure should not be recorded in
system.errors or consequently system.error_log. An exception that leaves such a scope must be
recorded explicitly with recordToSystemErrors before it propagates.

Apply the scope to the speculative direct and expression-template parsing paths in the Values
format. Propagated exceptions, including Decimal overflow, continue to be recorded.

Related: #109981

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):

The Values format no longer records parse errors in system.errors and system.error_log when streaming parsing successfully falls back to SQL expression parsing.

pamarcos added 4 commits July 20, 2026 21:58
The `Values` streaming parser uses parse exceptions to fall back to SQL expression parsing.
Those handled exceptions were recorded in `system.errors` and `system.error_log` even when the
insert succeeded.

Add a thread-local scope that suppresses system error accounting around the two speculative
parses. Exceptions that propagate, including `Decimal` overflow, are recorded explicitly before
they leave the parser.

Related: ClickHouse/support-escalation#8208
Alternative to: #109981
@clickhouse-gh

clickhouse-gh Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4073dff]

Summary: ❌

job_name test_name status info comment
Bugfix validation (unit tests) ERROR
Compile before-binary (ninja unit_tests_dbms, without the fix) ERROR

AI Review

Summary

This PR suppresses system.errors / system.error_log noise from speculative Values parser failures by adding Exception::SuppressErrorCodesScope and explicit recordToSystemErrors calls on propagated exceptions. The Values fixes and regression coverage look directionally right, but the new generic exception API still has correctness gaps around explicit re-recording, so I would not approve it yet.

Findings

⚠️ Majors

  • [src/Common/Exception.cpp:168-171] recordToSystemErrors is only idempotent per object instance. Copying a suppressed Exception preserves error_index == Suppressed, so std::exception_ptr, throw e, or any other by-value propagation can record the same logical failure multiple times. Suggested fix: share the suppressed/recorded state across copies, or narrow the public contract so copied exceptions cannot each re-record themselves.
  • [dismissed by author -- https://github.com/Do not record handled Values parse exceptions in system error tables #111141#discussion_r3624523868] [src/Common/Exception.cpp:171] Explicit re-recording still snapshots CurrentThread::getQueryId() at record time, not throw time. If a suppressed exception crosses a QueryIdSwitcher, background callback, or std::exception_ptr hop before recordToSystemErrors, system.errors.query_id / system.error_log.last_error_query_id will be attributed to the recorder rather than the original failing query.
Tests
  • ⚠️ Add a focused unit test that copies a suppressed Exception (for example through std::exception_ptr) and verifies that explicit recording still increments exactly once.
  • ⚠️ If the API is intended to be reusable beyond the narrow Values catch sites, add a regression test proving that recordToSystemErrors preserves original query attribution across explicit propagation, or document that such propagation is unsupported.
Final Verdict
  • Status: ⚠️ Request changes

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 20, 2026
@pamarcos
pamarcos requested a review from Copilot July 20, 2026 20:25

Copilot AI left a comment

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.

Pull request overview

This PR prevents handled Values-format parse exceptions (used for speculative streaming parsing before falling back to SQL expression parsing) from being counted in system.errors / system.error_log, while still ensuring that exceptions which propagate (including Decimal overflow) are explicitly recorded.

Changes:

  • Add Exception::SuppressErrorCodesScope (thread-local) to suppress system.errors accounting during speculative parsing, plus Exception::recordToSystemErrors to explicitly record propagated exceptions.
  • Apply suppression scopes in ValuesBlockInputFormat’s two speculative parse paths and explicitly record/rethrow non-parse-error exceptions and Decimal overflow.
  • Add a stateless query test verifying: (1) successful fallback doesn’t attribute errors to the async flush query, and (2) ARGUMENT_OUT_OF_BOUND overflow is still recorded.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Common/Exception.h Adds RAII suppression scope API and an explicit “record to system errors” method.
src/Common/Exception.cpp Implements thread-local suppression and explicit recording via ErrorCodes::increment.
src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp Suppresses accounting for speculative parses; explicitly records exceptions that will propagate.
tests/queries/0_stateless/04613_values_expression_fallback_no_system_errors.sh New regression test covering fallback behavior and overflow accounting.
tests/queries/0_stateless/04613_values_expression_fallback_no_system_errors.reference Expected output for the new test.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

pamarcos added 2 commits July 21, 2026 13:24
Drop fixed-name test tables before and after the test so interrupted runs do not leave state behind.
Map each asynchronous insert request to its flush query and check errors for that context. Enable
immediate failure for unexpected shell command errors.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Apply system-error suppression to expression-template probes as well as direct deserialization.
Record exceptions explicitly only when they propagate instead of falling back to another parser.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Cover the complete template-deduction attempt so unsupported AST nodes can fall back without
recording handled exceptions. Initialize the template parse result for clang-tidy.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Use named states for exceptions that were never recorded and exceptions whose accounting was
suppressed. Only the latter may be recorded explicitly when it propagates.
@pamarcos
pamarcos marked this pull request as ready for review July 21, 2026 17:36
Comment thread src/Common/Exception.cpp Resolved

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Comment thread src/Common/Exception.h Resolved
Document the preferred narrow scope and that explicit recording bypasses active suppression.
Cover active-scope recording in the unit test.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Comment thread src/Common/Exception.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 48.00% 86.20% +38.20%
Functions 60.60% 92.00% +31.40%
Branches 36.90% 78.30% +41.40%

Changed lines: Changed C/C++ lines covered: 90/98 (91.84%) · Uncovered code

Full report · Diff report

@pamarcos
pamarcos added this pull request to the merge queue Jul 23, 2026
@pamarcos

Copy link
Copy Markdown
Member Author

Ignoring the Bugfix validation job because the old code didn't have the recordToSystemErrors API

Merged via the queue into master with commit c1aeec1 Jul 23, 2026
351 of 354 checks passed
@pamarcos
pamarcos deleted the values-suppress-system-errors-minimal branch July 23, 2026 07:12
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 23, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…system-errors-minimal

Do not record handled `Values` parse exceptions in system error tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Development

Successfully merging this pull request may close these issues.

4 participants