Repository navigation
Conversation
…built InsertDependenciesBuilder::logQueryView guards thread_groups, view_types and inner_tables before building the log element, but the element builder read two more maps: select_queries.at(view_id) and select_contexts.at(view_id). observePath assigns select_contexts last, so a view that throws while its select context is being created keeps the three guarded maps populated and that one absent. The catch (...) in collectAllDependencies, reached only with materialized_views_ignore_errors enabled, then calls logQueryView on exactly that half-built view: view_id resolves to it because isView() is inner_tables.contains() and inner_tables was assigned before the throw. The guard passes and .at() throws std::out_of_range. Since the local catch (...) logs through tryLogCurrentException, getCurrentExceptionMessageAndPattern re-throws the std::logic_error into abortOnFailedAssertion, so a debug or sanitizer build aborts the server. A release build only logs it, and there the visible defect is a missing system.query_views_log row for the failed view. Build the element from what is available instead: a helper returns an empty view_query when either select map lacks the key. Extending the guard would drop the whole row and so remove the ExceptionBeforeStart record precisely when a view failed, which is the case the caller exists to record. An empty view_query was already representable, as getCleanQueryAst returns an empty string for a null AST. The guard itself is left alone, since it protects the fields that have no sensible empty value. The WINDOW branch has the same shape: it reads a parent select context before assigning its own, so either map can be the missing one. The other three logQueryView call sites read the same field and are covered by the same change; they were never separately affected, as they run only for views that reached chain construction. Found by Stress test (amd_debug), STID 2508-3f5e. The regression test drives the window deterministically: renaming a view's definer leaves the stored DEFINER name unresolvable, which throws from the statement that assigns the select context. It also covers a view whose definer resolves and fails later, and one that succeeds, so the empty-query assertion is shown to discriminate. Related: ClickHouse#104444
Internal second-model review (1 finding, no blockers)An independent cold review plus a second-model pass over the full diff. Both were
💡 Notes checked and found clean, listed only so they are not re-raised:
Session id: cron:clickhouse-review-slot-9:20260809-174600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260809-162800 |
|
cc @al13n321 @CheSema, could you review this? |
|
Workflow [PR], commit [8bfd4a9] Summary: ❌
AI ReviewSummaryThis PR fixes Final Verdict✅ No actionable issues found in the current PR state. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 11/12 (91.67%) · Uncovered code |
The style check rejects "fail" as a substring of a stateless test file name (ci/jobs/check_style.py:220-222 tests it with a plain "fail" in test_case, so "failed" matches), so the test and its reference are renamed to _broken_. The test also failed the Fast test because it wrote to stderr. Both of its views fail on purpose, the server logs each of those failures at warning level (InsertDependenciesBuilder.cpp:1651-1655, LogsLevel::warning), shell_config.sh forwards warnings to the client by default, and clickhouse-test fails a test that writes to stderr. Only errors are forwarded now, which is what the other tests provoking an expected server warning already do. Verified the suppression on the same server with a warning that does reach the client here: the Ordinary database deprecation warning arrives at --send_logs_level=warning and is gone at error. This sandbox never forwards the materialized view warning itself, so the test could not be reddened locally for that half.
Both views in the test fail on purpose. The server logs each of those failures at warning level (InsertDependenciesBuilder.cpp:1651-1655, LogsLevel::warning), shell_config.sh forwards warnings to the client by default, and clickhouse-test fails any test that writes to stderr. Only errors are forwarded now, which is what the other tests provoking an expected server warning already do. Verified the suppression on the same server with a warning that does reach the client here: the Ordinary database deprecation warning arrives at --send_logs_level=warning and is gone at error. This sandbox never forwards the materialized view warning itself, so the test could not be reddened locally for that half.
CI fix pushed - bbafc51Both reds were in the test this PR adds, not in the change under review. Style check ( Fast test ( One caveat stated plainly: my sandbox never forwards that materialized view warning The test passes through |
Build profile diff (arm_release)No arm_release build profile data for commit 8bfd4a9 - the build was skipped, reused from cache, or predates profile upload. |
The select state of a view is filled in two steps: the select query is stored first, then the select context. A view that throws in between reaches logQueryView with the query available but no context, and the previous version of getViewQueryForLog returned an empty view_query for that case, dropping an AST that was in fact present. That is the exact path this PR targets, so the field was empty precisely where it is most useful. getCleanQueryAst reads the context for log_queries_cut_to_length only, and logQueryView already takes every other logging setting from init_context, so init_context stands in for the missing one. The empty string is now reserved for a genuinely absent AST. Reported by the automated reviewer on the pull request.
The verification query listed the view names with concatWithSeparator, which is not suitable for constant folding, so under the old analyzer the IN set was rejected with BAD_ARGUMENTS before the query could read query_views_log. The error reached stderr and clickhouse-test failed the test on the old-analyzer shard while every other shard passed. The names are now built with the || operator, which folds under both analyzers and is the same idiom the neighbouring view_query comparison already uses.
|
Fixed the The verification query listed the view names with The names are now built with Verified under the failing shard's own setting, since a pass under the default analyzer proves nothing here: Unrelated to this PR, and I am not proposing to change it here: |
CI finish ledger - 8bfd4a9Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
On the two hung checks: I mapped every hung query in both
Session id: cron:our-pr-ci-monitor:20260810-150000 |
TimeSeries
|
|
Fixing PR for the hung |
6c8e5b1
Reproducer-- Server required. Reproduces on 26.7, 26.6, 26.5, 26.3, 25.8 (fixed on master).
CREATE USER dangling;
GRANT SELECT, INSERT ON *.* TO dangling;
-- Control: resolves, but cannot insert, so it fails only AFTER its select context is built.
CREATE USER present;
GRANT SELECT ON *.* TO present;
CREATE TABLE src (x UInt64) ENGINE = MergeTree ORDER BY x;
CREATE TABLE dst_dangling (x UInt64) ENGINE = MergeTree ORDER BY x;
CREATE TABLE dst_present (x UInt64) ENGINE = MergeTree ORDER BY x;
CREATE MATERIALIZED VIEW mv_dangling TO dst_dangling
DEFINER = dangling SQL SECURITY DEFINER AS SELECT x FROM src;
CREATE MATERIALIZED VIEW mv_present TO dst_present
DEFINER = present SQL SECURITY DEFINER AS SELECT x FROM src;
-- Leaves mv_dangling's stored DEFINER unresolvable, so building its select
-- context throws while its bookkeeping is only half filled.
ALTER USER dangling RENAME TO dangling_gone;
INSERT INTO src SETTINGS materialized_views_ignore_errors = 1, log_queries = 1, log_query_views = 1 VALUES (1);
SYSTEM FLUSH LOGS query_views_log;
SELECT view_name, status FROM system.query_views_log ORDER BY view_name;
-- Observed on 26.7.4.58: the INSERT itself fails with
-- Code: 1001. DB::Exception: std::exception. (STD_EXCEPTION)
-- std::out_of_range thrown from DB::InsertDependenciesBuilder::logQueryView
-- despite materialized_views_ignore_errors = 1, and query_views_log gets a row
-- for mv_present but none for mv_dangling.
-- Expected (master): INSERT succeeds, both views logged ExceptionBeforeStart.
-- On a debug/sanitizer build the same throw aborts the server.Results:
Backport the fix to CC component owner: @CheSema @al13n321 Analysis metadata
Introducing change: not identified
|
|
Verified the matrix independently before passing the request on. Ran your reproducer against the official binaries on The label for exactly those five branches is One caveat to carry: the cherry-pick will not apply cleanly on any of the five. Simulating @alexey-milovidov could you apply |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes a missing
system.query_views_logrow for a materialized view that fails while its dependencies are being collected withmaterialized_views_ignore_errorsenabled. In debug and sanitizer builds this also aborts the server withstd::out_of_rangeinstead of logging the view.Description
Related: #104444
InsertDependenciesBuilder::logQueryViewguards three maps before building the log element, but the element builder read five: it also didselect_queries.at(view_id)andselect_contexts.at(view_id), neither of which the guard covered.observePathfillsselect_contextslast, so a view throwing while its select context is created keeps all three guarded maps populated and that one absent. Thecatch (...)incollectAllDependencies(reached only withmaterialized_views_ignore_errors = 1) then callslogQueryViewon exactly that half-built view, the guard passes, and.at()throwsstd::out_of_range. The localcatch (...)logs throughtryLogCurrentException, so a debug or sanitizer build turns that intoabortOnFailedAssertionand the server aborts. A release build only logs it, and the visible defect there is a missingsystem.query_views_logrow.The fix builds the element from what is available. The select query is stored before the select context, so on this path the query is present and only the context is missing; a helper formats the stored query with
init_context, which supplies thelog_queries_cut_to_lengthcut-offgetCleanQueryAstreads from it and whichlogQueryViewalready uses for every other logging setting. An emptyview_queryis reserved for a genuinely absent AST. Extending the guard instead would drop the whole row, removing theExceptionBeforeStartrecord precisely when a view failed.The other three
logQueryViewcall sites read the same field and are covered by the same change. They run only for views that reached chain construction, so were never separately affected.Found by
Stress test (amd_debug)on an unrelated PR, STID2508-3f5e: CI report.Validated with a deterministic reproducer, added as a regression test: renaming a view's definer leaves the stored
DEFINERname unresolvable, throwing from the statement that assigns the select context. Pristine master aborts with the CI stack; with the fix the server stays up and logs oneExceptionBeforeStartrow keeping the view's query.Version info
26.8.1.1728(included in26.8and later)