Repository navigation
Conversation
Filtering `system.detached_tables` by `uuid` raised:
Code: 49. DB::Exception: Expected the argument №1 ('uuid' of type UUID)
to have 1 rows, but it has 0: while executing 'FUNCTION equals(uuid, ...)'
`getFilteredTables` builds an empty `uuid_column` when the WHERE clause
references `uuid`, but the `is_detached` branch only filled `table_column`.
`filterBlockWithExpression` then saw mismatched column lengths and threw.
Populate `uuid_column` from the detached iterator's `uuid()` to keep the
columns in lockstep. Also insert a default value for `engine_column`
defensively — `system.detached_tables` has no `engine` column today so
`filter_by_engine` cannot be true on that path, but this keeps the code
robust against future schema changes.
Adds regression test 04240_detached_tables_uuid_filter_102705.
Closes ClickHouse#102705
Pre-PR validation gatea. Deterministic repro? Yes. b. Root cause explained? Yes. c. Fix matches root cause? Yes. Populate d. Test intent preserved / new test added? New regression test e. Both directions demonstrated? Yes. Original repro crashed my local debug build with the exact stack trace from the issue ( f. Fix is general, not a narrow patch? Yes. The patch fixes the column-mismatch invariant at its source by always populating Session: |
|
cc @azat @alexey-milovidov — could you review? Trivial fix for #102705 ( |
|
Workflow [PR], commit [d17571c] Summary: ❌
AI ReviewSummaryThis PR fixes Final VerdictStatus: ✅ Approve |
| /// `system.detached_tables` has no `engine` column, so `filter_by_engine` | ||
| /// is never true for the detached path in practice. Insert a default value | ||
| /// defensively so the columns stay aligned if that ever changes. | ||
| if (engine_column) |
There was a problem hiding this comment.
Shouldn't we just not create engine_column above in case of is_detached?
Also it does not make sense to write comments for such a simple fix
There was a problem hiding this comment.
Done in 6e10f2f — engine_column is now never created on the detached path (guarded by !is_detached), and the comments are dropped. filter_by_engine && is_detached is logically unreachable anyway since system.detached_tables has no engine column and the analyzer rejects the predicate with UNKNOWN_IDENTIFIER before reaching getFilteredTables.
…ents - Guard engine_column creation with !is_detached so it's never allocated on the detached path. system.detached_tables has no engine column, so filter_by_engine cannot be true when is_detached (UNKNOWN_IDENTIFIER is raised at the analyzer level). - Remove the defensive engine_column->insertDefault() call which is no longer necessary. - Trim explanatory comments per reviewer feedback.
…ailure The reproducer for issue ClickHouse#102705 runs `SELECT ... FROM system.detached_tables WHERE uuid = ...` against a table that has already been detached. Without the fix, the planner creates `uuid_column` (because the predicate filters on `uuid`) but the detached branch of `getFilteredTables` leaves it empty while `table_column` has one row. The mismatched column lengths trigger a `LOGICAL_ERROR` which fires `chassert` in debug / sanitizer builds and aborts the process. When run via `clickhouse-client` against the long-running test server, that abort lands inside the server. The runner's hung-check then terminates the test before any result is recorded, so the `Bugfix validation` framework cannot invert the result to `OK` and the check fails on the PR (as observed on PR ClickHouse#104979). The original `.sql` form of `04240_detached_tables_uuid_filter_102705` had this issue. Switching the test to `.sh` and running the reproducer in `clickhouse local` contains the `SIGABRT` to a short-lived subprocess: stdout is truncated before reaching `SELECT 'ok'`, the runner sees the diff against the `.reference`, and reports a normal `FAIL`. Bugfix validation can then invert it to `OK` on the PR branch. The `.sh` uses the same pattern as `04238_kill_mutation_subquery_multi_block.sh` (PR ClickHouse#104927) and `01600_detach_permanently.sh` (Atomic database under `--path` + `${CLICKHOUSE_TEST_UNIQUE_NAME}` working folder). Verified locally on the rebuilt debug binary: - with the fix → `1\nok` → matches reference (30 / 30 deterministic). - without the fix (line 118-119 reverted, rebuilt) → `Aborted (core dumped)` with empty stdout → does not match reference → `FAIL`. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Pushed Diagnosis: The regression test in its previous Fix: Converted the test to Local verification (debug build):
The other red check, Session: cron:clickhouse-ci-task-worker:20260515-174500 |
LLVM Coverage Report
Changed lines: 100.00% (8/8) · Uncovered code |
532614c
|
Hi @groeneai @azat — the changelog category for this PR might need a look. Current: Why: LOGICAL_ERROR exceptions are internal assertion failures (chassert in debug builds) that indicate contract violations. This category applies when the server detects an internal inconsistency. The PR description confirms this is Code 49 LOGICAL_ERROR. Could you verify this is correct? Ignore if the current category is intentional. |
|
Hi — could this be a backport candidate for Affected code: Why this might apply: The bug was introduced in commit 51d293b (2024-06-28) when Caveat: I verified that the modified code exists in those branches, but not whether the bug is actually reachable there — a new caller in master may be what makes this newly observable. If older branches can't reach the affected path, please ignore this; otherwise consider |
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/2077 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
Closes #102705.
What is the bug
Filtering
system.detached_tablesbyuuidraises aLOGICAL_ERRORand aborts in debug builds:Root cause
detail::getFilteredTablesis shared betweensystem.tablesandsystem.detached_tables. When the WHERE clause references theuuidcolumn, the function creates auuid_columnto feed the filter expression. The non-detached branch fillsuuid_columnfromtable->getStorageID().uuid, but theis_detachedbranch only filledtable_column. After the loop, both columns are inserted into the sameBlock:VirtualColumnUtils::filterBlockWithExpressionthen executesequals(uuid, '<literal>'), andcheckFunctionArgumentSizesraisesLOGICAL_ERRORbecause the columns have mismatched lengths.Fix
Populate
uuid_columnfrom the detached iterator'suuid()so the columns stay in lockstep.DatabaseDetachedTablesSnapshotIteratoralready exposesuuid()(it is used elsewhere inStorageSystemDetachedTables.cpp).engine_columncannot currently be created on the detached path —system.detached_tableshas noenginecolumn, so the predicate cannot reference it — but a defensiveengine_column->insertDefault()is added so the loop stays correct if that schema is ever extended.Reproduction
The query above crashed the local debug build before this change; with the fix it returns the expected count and the server stays up. The new regression test exercises three failing query shapes (lookup by uuid via subquery, by direct uuid comparison after detach, and uuid-only filter).
Documentation entry for user-facing changes
Information about CI checks
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed a
LOGICAL_ERRORthrown when filteringsystem.detached_tablesbyuuid(e.g.SELECT count() FROM system.detached_tables WHERE uuid = '...'). The query now returns the expected result instead of aborting the server.Version info
26.5.1.749