Skip to content

Log a query_views_log row for a view that failed before it was fully built - #114064

Merged
al13n321 merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-log-query-view-half-built-select-state
Aug 20, 2026
Merged

al13n321 merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-log-query-view-half-built-select-state

Conversation

@groeneai

@groeneai groeneai commented Aug 9, 2026 •

Copy link
Copy Markdown
Collaborator

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

Fixes a missing system.query_views_log row for a materialized view that fails while its dependencies are being collected with materialized_views_ignore_errors enabled. In debug and sanitizer builds this also aborts the server with std::out_of_range instead of logging the view.

Description

Related: #104444

InsertDependenciesBuilder::logQueryView guards three maps before building the log element, but the element builder read five: it also did select_queries.at(view_id) and select_contexts.at(view_id), neither of which the guard covered.

observePath fills select_contexts last, so a view throwing while its select context is created keeps all three guarded maps populated and that one absent. The catch (...) in collectAllDependencies (reached only with materialized_views_ignore_errors = 1) then calls logQueryView on exactly that half-built view, the guard passes, and .at() throws std::out_of_range. The local catch (...) logs through tryLogCurrentException, so a debug or sanitizer build turns that into abortOnFailedAssertion and the server aborts. A release build only logs it, and the visible defect there is a missing system.query_views_log row.

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 the log_queries_cut_to_length cut-off getCleanQueryAst reads from it and which logQueryView already uses for every other logging setting. An empty view_query is reserved for a genuinely absent AST. Extending the guard instead would drop the whole row, removing the ExceptionBeforeStart record precisely when a view failed.

The other three logQueryView call 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, STID 2508-3f5e: CI report.

Validated with a deterministic reproducer, added as a regression test: renaming a view's definer leaves the stored DEFINER name 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 one ExceptionBeforeStart row keeping the view's query.

Version info

  • Merged into: 26.8.1.1728 (included in 26.8 and later)

…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
@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (1 finding, no blockers)

An independent cold review plus a second-model pass over the full diff. Both were
run before this PR was opened; nothing below is outstanding.

⚠️ PR metadata format — AGREED, fixed before opening. The changelog entry was in
past tense ("Fixed a missing ... row"), but
docs/changelog_entry_guidelines.md requires the present tense and gives the
same example ("Instead of: Fixed a crash ... / Write: Fixes a crash ..."). The
visible relationship line also used the abbreviated #104444 where
.github/PULL_REQUEST_TEMPLATE.md asks for full GitHub URLs. Both corrected.

💡 Notes checked and found clean, listed only so they are not re-raised:

  • The test is untagged, while the four other tests combining CREATE USER with a
    DEFINER materialized view carry no-replicated-database, no-async-insert. I
    measured the two untagged members of that family over 30 days instead of
    copying the convention: 04401 and 04404 are green on both the AsyncInsert
    and DBReplicated shards in roughly 37,000 runs, with no failure on either. So
    the tag is a per-test necessity there, not a class requirement, and adding it
    pre-emptively would shield the new test for no measured reason.
  • Test liveness was traced, not assumed. Pristine master aborts with the frames
    from the CI report; a mutation that reverts only the helper body to .at()
    aborts again. Within one log, mv_present shares the asserted status and
    differs only in the empty-query column, so that column is shown to
    discriminate.
  • I enumerated the log element's map reads independently before comparing against
    the plan; the lists agree, and after this change the element builder reads no
    map the guard does not cover. logQueryView is the only builder of
    QueryViewsLogElement in the tree, so there is no symmetric writer to mirror.
  • On a release build this turns "no row" into "one row with an empty
    view_query". That is the intended change and it is stated in the description;
    the empty value was already producible, so no format or setting change follows.

Session id: cron:clickhouse-review-slot-9:20260809-174600

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. ALTER USER <definer> RENAME TO ... then a logged INSERT with materialized_views_ignore_errors = 1. The rename path is not guarded by DefinerDependencies (unlike DROP USER, which refuses with HAVE_DEPENDENT_OBJECTS), so the stored DEFINER name stops resolving and getDefinerID throws from the statement that assigns select_contexts[current]. No fault injection, no memory tuning, no probability.
b Root cause explained? Yes. logQueryView guards thread_groups, view_types, inner_tables, but its element builder also read select_queries.at() and select_contexts.at(). observePath assigns select_contexts last, so a throw inside createSelectInsertContext leaves the guarded trio populated and that one absent. The pre-construction catch (...) resolves view_id to that same half-built view (isView is inner_tables.contains, set earlier), the guard passes, and .at() throws std::out_of_range. tryLogCurrentException then routes a std::logic_error into abortOnFailedAssertion in debug and sanitizer builds.
c Fix matches root cause? Yes. The defect is that the element builder assumed fully-built state its own guard did not cover, so the one field whose inputs can be absent now tolerates absence. Not a widened bound, not a no-random-* tag, not a check that masks an upstream problem. Extending the guard instead was rejected because it would drop the whole row exactly when a view failed, which is the case the caller exists to record.
d Test intent preserved / new tests added? New stateless regression test added, no existing test weakened or removed. It asserts a row is still produced rather than only that nothing aborts, so it also pins the behaviour the rejected alternative would have removed.
e Both directions demonstrated? Yes. Pristine master exits 134 (SIGABRT) with frames matching the CI report (logQueryView -> SystemLogBase::add -> out_of_range, then Exception.cpp:548 -> abortOnFailedAssertion). With the fix the server stays up and logs one ExceptionBeforeStart row with an empty view_query. Both arms on Build-ID-verified binaries. Additionally, reverting only the helper body to .at() reproduces the abort through the new frame, so the guard is load-bearing and the test genuinely reddens without it.
f Fix is general across code paths? Yes. All four logQueryView call sites route through the single view_query read, so one change covers them all. The other three (FinalizingViewsTransform::writeViewLogs) were never separately affected, since they run only for views that reached chain construction. After the fix the element builder reads no unguarded map, so the guard and the builder are consistent. logQueryView is the only builder of QueryViewsLogElement, so no symmetric writer needs the same treatment.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. The helper checks both maps independently, covering the MATERIALIZED case (select_contexts missing) and the WINDOW case (either missing, since it reads a parent context before assigning its own). No type-wrapper surface: the value is a String built from an AST, and getCleanQueryAst already returns an empty string for a null AST, so an empty value was already representable in that column.
h Backward compatible? (maintainer-approved exception only) Yes. No setting added or defaulted differently, so no SettingsChangesHistory.cpp entry; no serialization or format change; view_query stays a String. The only behaviour change is that a half-built failing view now yields a row with an empty view_query where it previously yielded none, which is strictly more information and is stated in the PR body.
i Invariants and contracts preserved? Yes. The existing guard is deliberately left in place: it protects the three fields with no sensible empty value (view_type, view_target, and thread_group, which is dereferenced for timing and profile counters). The helper is const, takes the key the caller already validated, performs two lookups and allocates nothing on the absent path. No lock, ownership, or error-path behaviour changes.

Session id: cron:clickhouse-impl-slot-41:20260809-162800

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

cc @al13n321 @CheSema, could you review this? logQueryView guarded three of the five maps its log-element builder reads, and observePath assigns select_contexts last, so a view that throws while its select context is being built passes the guard and then hits .at() on the absent key, which aborts debug and sanitizer builds through tryLogCurrentException. It keeps the row and degrades only view_query, rather than extending the guard and dropping the ExceptionBeforeStart record exactly when a view failed.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8bfd4a9]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, azure, sequential) FAIL
04320_query_condition_cache_topk_correctness FAIL cidb
Stress test (amd_msan) FAIL
Hung check failed, possible deadlock found FAIL cidb
Stress test (arm_asan_ubsan, s3) FAIL
Hung check failed, possible deadlock found FAIL cidb

AI Review

Summary

This PR fixes InsertDependenciesBuilder::logQueryView so a system.query_views_log row is still emitted when dependency collection fails after select_queries is populated but before select_contexts exists, and it adds a regression test for that materialized_views_ignore_errors = 1 path. I did not find any remaining correctness, metadata, or test-contract issues in the current PR state.

Final Verdict

✅ No actionable issues found in the current PR state.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.60% -0.10%
Functions 91.80% 91.90% +0.10%
Branches 78.90% 78.90% +0.00%

Changed lines: Changed C/C++ lines covered: 11/12 (91.67%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 9, 2026
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.
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI fix pushed - bbafc51

Both reds were in the test this PR adds, not in the change under review.

Style check (functional_tests_check): ci/jobs/check_style.py:220-222 rejects
fail as a plain substring of a stateless test file name, and failed matches.
Renamed the test and its reference to 04736_query_views_log_view_broken_before_start.
The number is unchanged, so the numbering-gap check is unaffected.

Fast test (having stderror): both views in the test fail on purpose, the server
logs each failure 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. The test now passes
--send_logs_level=error, as the other tests provoking an expected server warning
already do.

One caveat stated plainly: my sandbox never forwards that materialized view warning
to the client at any level, so I could not redden the test locally for the stderr
half. What I did verify on the same server is the gate the fix relies on, using a
warning that does reach the client here - the Ordinary database deprecation warning
arrives at --send_logs_level=warning and is gone at error. Same priority, same
InternalTextLogsQueue::isNeeded gate as the leaked message.

The test passes through clickhouse-test and 16 of 20 randomized runs; the 4
failures are a local sandbox property (INCONSISTENT_CLUSTER_DEFINITION, no
parallel_replicas cluster on a bare server) and the untouched master sibling
01927_query_views_log_matview_exceptions fails 20 of 20 the same way in that
sandbox.

@clickhouse-gh

clickhouse-gh Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Collaborator Author

Fixed the Stateless tests (amd_llvm_coverage, old analyzer, ...) failure of the new test in 8bfd4a94a2ffb4d. Test-only, 1 file, +3/-3.

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 Code: 36 BAD_ARGUMENTS before the query could read query_views_log. The error reached stderr and clickhouse-test failed on the stderr rule. Mechanism: ConcatWithSeparatorImpl does not override useDefaultImplementationForConstants(), unlike FunctionConcat (src/Functions/concat.cpp:49), so ActionsDAG::tryFoldFunctionToConstant never yields a const column and evaluateConstantExpression finds none. Measured isConstant(concatWithSeparator('.','a','b')) = 0 under both analyzers; only the tolerance of the IN path differs. An all-literal argument list is rejected too, so currentDatabase() is not the trigger.

The names are now built with ||, the idiom the neighbouring view_query comparison in the same query already uses.

Verified under the failing shard's own setting, since a pass under the default analyzer proves nothing here: enable_analyzer=0 OK and enable_analyzer=1 OK; restoring the old predicate reddens under enable_analyzer=0 only, reproducing the CI error text exactly. 20 randomized runs alternating the analyzer: 19 OK, 0 reference diffs, the single failure being a local sandbox Requested cluster 'parallel_replicas' not found, which an untouched master sibling test hits 10 out of 10 times in the same sandbox.

Unrelated to this PR, and I am not proposing to change it here: concatWithSeparator is unusable in any constant-expression position (IN set, LIMIT, table function argument) while concat works there, and in the IN case the two analyzers disagree about it.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 8bfd4a9

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens.

Check / test Reason Owner / fixing PR
Stateless tests (arm_asan_ubsan, azure, sequential) / 04320_query_condition_cache_topk_correctness flaky, not caused by this PR (result differs with reference; 7 unrelated PRs and 2 master runs in 30 days) #113011 (external, merged 2026-08-10 14:24Z; this run started 12:27Z so it predates the fix, and it is picked up on the next push)
Stress test (amd_msan) / Hung check failed, possible deadlock found a cancelled DROP TABLE of a TimeSeries table never returns from waitTableFinallyDropped, and DROP/DETACH DATABASE convoy behind it in getDDLGuard a fix task is created (investigating at full effort, fixing-PR link to follow on this PR)
Stress test (arm_asan_ubsan, s3) / Hung check failed, possible deadlock found same signature and same root query, reproduced independently on this second arm a fix task is created (investigating at full effort, fixing-PR link to follow on this PR)

On the two hung checks: I mapped every hung query in both hung_check.log artifacts to its own
stack frames. On each arm the oldest query is a cancelled DROP TABLE prometheus and it is the
only one in waitTableFinallyDropped with a StorageTimeSeries frame, while each later query
targets the same test database and waits on a plain mutex in getDDLGuard. So this is one stuck
holder with a queue behind it, not several defects, and it is unrelated to this PR's diff
(InsertDependenciesBuilder). My merged #107604 and #113504 are both already ancestors of this
head, so neither covers it: #107604 is scoped to Replicated databases and #113504 to the
CREATE ... AS SELECT cleanup path, whereas this reaches the same wait from a plain
InterpreterDropQuery.

Build (arm_release) / Post Hooks is not listed for the reason given above: its CIDB FAIL
row accompanies a check that concludes success on GitHub and appears on 815 PRs in 7 days. The
run is genuinely finished with coverage: 175 jobs, 154 OK, 18 skipped, 3 failing, 0 dropped.

Session id: cron:our-pr-ci-monitor:20260810-150000

@groeneai

Copy link
Copy Markdown
Collaborator Author

TimeSeries DROP hung check: root cause found, but no fix PR from me

Conclusion first, so nobody waits on me: no fixing PR. The one-line fix is measurably wrong,
and the defect that actually reddens CI is not reproducible with any failpoint currently in the
tree. Writing up what I measured in case somebody who owns this code wants to take it.

Symptom. One DROP TABLE prometheus stuck in DatabaseCatalog::waitTableFinallyDropped with
is_cancelled = 1 for 470-3971 s, with every other hung query a DDL-guard victim behind it
(same test database, strictly smaller elapsed). fatal.log empty: a hang, not an abort.
Carrier is 04811_promql_topk_bottomk_limitk[_streaming]. Seen on master too
(3d6b762118b8 amd_msan, 7fc48be1accb arm_asan_ubsan+s3), so it is not PR-specific.

Two stacked defects.

  1. The wait never completes. In the amd_msan server log, 641 tables enter the wait and 640
    leave; exactly one never does. The drop-queue in-use count goes 0 -> 1 five seconds after that
    wait begins and never returns to 0 (Have 3 tables in drop queue (2 of them are in use)
    through the end of the log, ~12 min later). getTablesToDrop skips any entry that is not
    isSharedPtrUnique, so one surviving StoragePtr to the inner .inner_id.samples.* table
    makes the entry permanently unreachable and the wait's loop condition true forever. I could
    not identify which reference survives.
  2. The wait is unkillable. InterpreterDropQuery::executeDropQuery builds the inner drop's
    context from Context::createCopy(global_context) and copies the caller's settings, so the
    randomized database_atomic_wait_for_drop_and_detach_synchronously = 1 is inherited and the
    inner drop waits, but no process-list element is ever set. throw_if_cancelled is therefore a
    no-op and cancellation cannot break the loop.

Why I am not sending the obvious patch. Propagating the process-list element onto that inner
context makes the DROP killable and converts the hang into a permanently half-dropped table:
DatabaseAtomic::dropTable calls dropInnerTableIfAny before dropTableImpl, so the new
cancellation throw aborts the parent's own removal. Measured A/B, both arms with build IDs
asserted against the binaries: after the failpoint is released the base arm completes the drop
correctly (0 tables) while the patched arm leaves 3 tables permanently, system.dropped_tables
empty, and CREATE TABLE ... ENGINE = TimeSeries then fails with TABLE_ALREADY_EXISTS. I had
already implemented, measured and reverted this exact line once before, on #113504.

Why the ordering repair is not mine to make either. Dropping the parent first would need
durable, idempotent inner-table recovery in every storage that owns inner tables.
StorageMaterializedPostgreSQL does not override drop() at all (IStorage::drop() is empty),
so a crash in that window strands its nested table with no fallback, and
StorageWindowView::dropInnerTableIfAny is non-idempotent and swallows exceptions. The existing
inner-first comments in DatabaseAtomic and DatabaseReplicated look deliberate.

What would unblock defect 1. Every pauseable failpoint on this path
(database_catalog_drop_finally_before_id_erase) pauses after dropTableFinally has already
passed the isSharedPtrUnique gate, so it cannot construct the state that hangs. A failpoint
upstream of that gate, or a coredump from a live occurrence, would let me name the holder and
propose something narrow. Without either I would only be guessing, so I am stopping here rather
than shipping a speculative guard.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the hung DROP TABLE of a TimeSeries table (waitTableFinallyDropped): #114302 (external, open).

@al13n321
al13n321 added this pull request to the merge queue Aug 20, 2026
Merged via the queue into ClickHouse:master with commit 6c8e5b1 Aug 20, 2026
178 of 182 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 20, 2026
@clickgapai

Copy link
Copy Markdown
Contributor
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:

  • Culprit PR: not pinned — introduced in the 25.1–25.6 window (details in Analysis metadata)
  • Reproduces on: 26.7, 26.6, 26.5, 26.3, 25.8
  • Does not reproduce on: master
  • Tested versions: master, 26.7, 26.6, 26.5, 26.3, 25.8
  • Also tested (unsupported, context only): 26.2 reproduces
  • ✓ Fix is on master — this PR's change fixes the bug on master. The releases listed above still have the bug and need the backport.

Backport the fix to 26.7, 26.6, 26.5, 26.3, 25.8.

CC component owner: @CheSema @al13n321

Analysis metadata

comp-materialized-view · Severity P2 · Finding phase_d_pr114064

  • Verified against master build 6c8e5b1397b5 (aarch64)
Introducing change: not identified
  • The introducing change was not identified.
  • Release-level boundary (official release binaries): first reproduces at v25.6.3.116-stable.
  • Candidate range: the introducing PR is one of those merged between Update version after release #80278 and Revert "Revert "rework pushing to views #77309"" #79963.
  • A source-build bisect over the range was attempted but could not produce a verdict; the range above is the most precise information available.
  • Walked 4 release(s) below the supported window: still reproduces down to 25.6.
  • Secondary components: comp-testing

@groeneai

Copy link
Copy Markdown
Collaborator Author

Verified the matrix independently before passing the request on.

Ran your reproducer against the official binaries on builds.clickhouse.com, with a master control.
All five reproduce, master does not: 26.7.5.4, 26.6.4.4, 26.5.8.5, 26.3.20.8, 25.8.31.10
each fail the INSERT with Code: 1001 from DB::InsertDependenciesBuilder::logQueryView and log 0
rows, while 26.8.1.1746 succeeds and logs both views as ExceptionBeforeStart. Two details worth
adding: master logs the row for the broken view as well as the healthy one, and on the release
binaries the INSERT fails even with materialized_views_ignore_errors = 1, so that setting does not
contain it. 26.2 is out of scope, its release PR is not among the active ones.

The label for exactly those five branches is v25.8-must-backport, computed with
select_backport_branches (tests/ci/cherry_pick_branches.py) against the active release PRs
(#111451, #108336, #105429, #100062, #86119). pr-must-backport covers the same set here but is the
blanket form.

One caveat to carry: the cherry-pick will not apply cleanly on any of the five. Simulating
cherry_pick.py:298-345 gives a content conflict in src/Interpreters/InsertDependenciesBuilder.cpp
on all five and a second one in the header on 25.8 (control: the same simulation on #112327 returns
clean for 26.6/26.5/26.3, which is what happened there). It is positional, not semantic: master nests
the logQueryView body one indent level deeper, so the single changed line does not match, but the
statement is byte-identical on all five and every prerequisite is already present. Resolving it is
taking the master side of one line and re-indenting it. There is no 04736_ collision on any branch.

@alexey-milovidov could you apply v25.8-must-backport here. I am not hand-authoring the backports,
per @ pufit's instruction that you confirmed on #111910.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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.

5 participants