Repository navigation
Fix logical error on filter push-down with a differently-typed same-name column - #113984
Conversation
…ame column A predicate typed against a view header (e.g. `information_schema.tables`, where `engine` is `Nullable(String)`) could be pushed down to the underlying storage (`system.tables`, where `engine` is `String`) and evaluated over a block with the mismatched column type, failing with a logical error `Unexpected return type from toString. Expected Nullable(String). Got String`. Two fixes: - `buildFilterActionsDAG`: skip a name-based input replacement when it would change the input type. Parent `FUNCTION` nodes are rebuilt with their existing `function_base`, so a differently-typed input made the rebuilt DAG (including the DAG captured inside `indexHint`) internally inconsistent. - `canEvaluateSubtree` in `VirtualColumnUtils`: match the allowed inputs by type as well as by name, so a mismatched predicate subtree is not pushed down (the filter is still applied upstream). Found by the AST fuzzer: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113636&sha=bea222ed980b6db96146b4fe56dc968fa2280dd1&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29 on #113636 Closes: #113982 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [0d91aad] Summary: ✅
AI ReviewSummaryThis PR makes filter push-down fail closed when a pushed predicate would bind a same-name column with a different type, and it fixes the Missing context / blind spots
Final VerdictNo blocking issues found in the current head. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 25/25 (100.00%) · Uncovered code |
The test scanned the whole `information_schema.tables`, so `system.tables` computed `total_rows` for every table on the server. In a parallel stateless run this hits other tests' half-dropped tables (e.g. a DeltaLake table whose path was already removed), and their errors are streamed to the client as server logs, failing the test with non-empty stderr: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113984&sha=ea086a58d6d2f255bbbde02f94e35ab84c4a64c7&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29 Add a `table_schema = currentDatabase()` conjunct to each query (verified via the `SelectedRows` profile event that it is pushed down into `system.tables`, so only the current database is enumerated) and create a table so the block the predicate is evaluated over is non-empty. Verified that the modified test still reproduces the logical error on a pre-fix binary and passes with the fix. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 CI adjudication for head
|
Build profile diff (arm_release)No arm_release build profile data for commit 0d91aad - the build was skipped, reused from cache, or predates profile upload. |
The push-down sample blocks in `detail::getFilteredTables` and `ReadFromSystemTables::applyFilters` declared `uuid` as `String`, while the real column of `system.tables` / `system.detached_tables` (and the block the split-off predicate is evaluated over) is `UUID`. The name-only input matching used to hide this; with the exact-type check in `splitFilterDagForAllowedInputs`, the lying sample would silently disable the `uuid` prefilter fast path, forcing the source to materialize every table row before the outer filter. Declare the sample truthfully and add a test that pins the fast path via the `SelectedRows` profile event (1 with the prefilter, one row per table in the database without it). Verified: the test fails without this change and passes with it. Addresses the AI review finding on the pull request. Co-Authored-By: Claude Fable 5 <[email protected]>
Since `max_insert_threads` started to apply to plain `INSERT`s (ClickHouse#109000), an insert fans out to multiple parallel `MergeTreeSink`s (the default `max_insert_threads = 0` resolves to the number of cores). Each sink ran the "too many parts" throw check in `onStart`, and nothing guarantees all `onStart`s complete before a sibling sink commits its part: a sink whose `onStart` ran late (e.g. its worker thread was preempted on a loaded machine) counted the parts committed by its sibling sinks and spuriously rejected with `TOO_MANY_PARTS` the very insert that wrote them. This made `02458_relax_too_many_parts` flaky fleet-wide (~5-11 failures/day since 2026-08-01), e.g.: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113984&sha=ea086a58d6d2f255bbbde02f94e35ab84c4a64c7&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29 on ClickHouse#113984 Move the throw check to `StorageMergeTree::write` / `StorageReplicatedMergeTree::write`, which run on the query thread while the insert pipeline is being built, so the check never sees the query's own parts. The sinks' `onStart` keeps the delay-under-pressure behavior (`allow_throw = false`), where the parallel streams sleep concurrently; the new `allow_delay = false` mode of `delayInsertOrThrowIfNeeded` avoids sleeping once per sink stream on the query thread. Add the `merge_tree_sink_on_start_random_sleep` failpoint, which skews the sinks' start times, making the race deterministic: with the failpoint, the new test `04826_parallel_insert_sinks_too_many_parts_self_race` fails 5/5 with the pre-fix behavior and passes 5/5 with the fix. Closes: ClickHouse#114015 Co-Authored-By: Claude Fable 5 <[email protected]>
ReproducerCREATE VIEW v AS SELECT toNullable(engine) AS engine FROM system.tables;
SELECT 1 FROM (SELECT 1 FROM v WHERE indexHint(toString(engine))) FORMAT Null;
-- Code: 49. DB::Exception: Unexpected return type from toString. Expected Nullable(String). Got String. (LOGICAL_ERROR)
-- Reproduces on 26.7.3.19 down to 24.5.8.10; clean on 24.4.4.113 and on master after this PR.Results:
Backport the fix to CC component owner: @alexey-milovidov @KochetovNicolai Analysis metadata
Introducing change: not identified
|
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix a logical error (
Unexpected return type) when a filter over a view whose column type differs from the underlying storage (e.g.information_schema.tables, whereengineisNullable(String), oversystem.tables, where it isString) is pushed down to the storage.Minimal reproducer:
The predicate is typed against the view header, where
engineisNullable(String). WhenSourceStepWithFilter::applyFiltersrebuilds the filter withActionsDAG::buildFilterActionsDAG, the name-based input replacement substituted the storage columnengine Stringfor the input while the parentFUNCTIONnodes were rebuilt with their existingfunction_base— leaving the rebuilt DAG (including the DAG captured insideindexHint) internally inconsistent:toStringstill declaredNullable(String)while returningString. Evaluating it over the candidate-tables block ingetFilteredTablesthen failed the return-type assertion inExpressionActions.Two fixes:
ActionsDAG::buildFilterActionsDAG: skip a name-based input replacement when it would change the input type. Keeping the original input is safe — the subtree is then simply not evaluated over the storage columns, and the filter is still applied upstream.canEvaluateSubtreeinVirtualColumnUtils: match the allowed inputs by type as well as by name, as a fail-close guard at the evaluation site, so a mismatched predicate subtree is not pushed down.The exact-type check exposed a lying push-down sample in
StorageSystemTables: bothdetail::getFilteredTablesandReadFromSystemTables::applyFiltersdeclareduuidasStringwhile the real column ofsystem.tables/system.detached_tablesisUUID, which would have silently disabled theuuidprefilter fast path. The samples now declareUUID, and a test pins the fast path via theSelectedRowsprofile event.Found by the AST fuzzer on two unrelated PRs (pre-existing on
master; the same error also appears inmasterstress tests going back months): AST fuzzer (amd_debug) report.Closes: #113982
Related: #113636
Version info
26.8.1.1195(included in26.8and later)