Repository navigation
Fix Parquet v3 reader logical error on key-condition column with no file mapping - #109267
Conversation
The Parquet v3 reader maps each column referenced by the format-level key_condition to a file-readable output column, to enable row-group min/max pruning. It asserted (LOGICAL_ERROR) when the mapping was absent, on the assumption that the key condition only references columns read from the file. The AST fuzzer's internal execution path can construct a key_condition that references a column not read from the file (e.g. a PREWHERE output produced by match(<non-const>, s), which normal SQL rejects with Code 44 before it reaches the reader). The mapping is then absent and the reader aborts. A key-condition column with no file-readable output column has no column-chunk statistics, so it cannot participate in row-group pruning. Leave its range as the whole universe (skip it), exactly as the reader already does for a column whose min/max statistics are missing. The query that would otherwise succeed keeps returning correct, unpruned results, and the abort is removed. Found by the AST fuzzer (issue ClickHouse#107951, site 6). Not reproducible via client SQL: the analyzer rejects the trigger before execution. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260703-092701 |
|
cc @al13n321 @scanhex12 could you review this? The Parquet v3 reader threw a LOGICAL_ERROR when the format-level key condition references a column not read from the file (reachable only on the AST-fuzzer internal path). The fix skips such a column for row-group pruning instead of asserting, exactly as it already does for a column with missing min/max stats. Issue #107951 (site 6). |
|
Workflow [PR], commit [ddd60e5] Summary: ✅
AI ReviewSummaryThis PR removes the Final VerdictStatus: ✅ Approve |
The row-group pruning loop was fixed to skip a key-condition column with no file-readable output column (no column-chunk stats). The page-index setup runs extractSingleColumnConditions right after and mapped the same column indices; with input_format_parquet_page_filter_push_down enabled (default), an unmapped column still threw LOGICAL_ERROR "Column condition uses PREWHERE output", so the AST-fuzzer shape could still abort before any data is read. An unmapped column has no page-index statistics either, so it cannot participate in page-level pruning. Skip it there too (page-level pruning is disabled for that condition), matching the row-group site. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260703-114900 |
CI finish ledger - 4c737a7CI fully finished (Finish Workflow SUCCESS). No failed checks. This PR fixes the Parquet v3 reader logical error on a key-condition column with no file mapping (both the row-group-pruning and page-index sites), related to #107951. No failures to attribute. Session id: cron:our-pr-ci-monitor:20260703-163000 |
|
@groeneai, Logical error does not lead to server abort in the release build - it is just an exception. Correct the description and remember this. |
|
@alexey-milovidov Corrected. The description, changelog entry, and comments no longer describe the LOGICAL_ERROR as a release-build abort; it is a caught exception in release builds and aborts only in debug and sanitizer builds. No code change. |
|
The bugfix validation check should have failed here, but it didn't fail. We have to figure out why. |
|
The AST fuzzer constructed a query that failed: Why can it not be reproduced with a test? |
Ok, this is solved. It is green, because the PR description has a link to CI report. |
…output crash The `KeyCondition uses PREWHERE output` logical error in the Parquet v3 reader is reproducible with a plain SQL test after all. The trigger is not the non-constant `match` pattern, but the combination of an aggregate (so the key-condition column is never read as an output column) with both a `PREWHERE indexHint(...)` and a `WHERE indexHint(...)` on that column, under the old analyzer (`enable_analyzer = 0`). Verified against downloaded CI debug builds: the test crashes on master HEAD (`SIGABRT`, `Logical error: 'KeyCondition uses PREWHERE output'` at `Reader.cpp:370`) and passes on this PR, so per-arch Bugfix validation now catches the fix. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
@alexey-milovidov You are right, and thanks for the test. It does reproduce from plain SQL under the old analyzer ( |
The test used a fixed file('04498.parquet') in the shared user_files dir.
Under the flaky check it runs many times concurrently; one iteration's
INSERT ... engine_file_truncate_on_insert=1 truncated the file to 0 bytes
while a concurrent iteration read it, giving Code 117 'Parquet file too
short: 0 bytes' / Code 636 'file is empty'.
Rewrite as a .sh test using clickhouse-local and a per-test unique file
($CLICKHOUSE_TMP/$CLICKHOUSE_TEST_UNIQUE_NAME.parquet), so concurrent runs
never collide. Same three queries and same 0/10/0 reference; test intent
(detect the 'KeyCondition uses PREWHERE output' logical error) unchanged.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
The flaky check failed on the new test: it used a fixed Rewrote it as a |
CI finish ledger — 1275d5dEvery failure below has an owner. Only
Session id: cron:our-pr-ci-monitor:20260708-050000 |
…-site6-parquet-keycond-unmapped
…test comment The style check rejects the wording "new analyzer" because the analyzer is enabled by default since 24.3 and is no longer new. The Style check failure also dropped all downstream jobs including Bugfix validation, which made Finish Workflow red. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109267&sha=b5e76b6e2755e911c785fa9d04205ce7a2b2eda7&name_0=PR&name_1=Style%20check PR: ClickHouse#109267 Co-Authored-By: Claude Fable 5 <[email protected]>
…-site6-parquet-keycond-unmapped
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 12/12 (100.00%) · Uncovered code |
…test comment The style check rejects the wording "new analyzer" because the analyzer is enabled by default since 24.3 and is no longer new. The Style check failure also dropped all downstream jobs including Bugfix validation, which made Finish Workflow red. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109267&sha=b5e76b6e2755e911c785fa9d04205ce7a2b2eda7&name_0=PR&name_1=Style%20check PR: ClickHouse#109267 Co-Authored-By: Claude Fable 5 <[email protected]>
…1-site6-parquet-keycond-unmapped Fix Parquet v3 reader logical error on key-condition column with no file mapping
Related: #107951 (AST fuzzer, site 6)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a logical error (
Logical error: 'KeyCondition uses PREWHERE output') in the Parquet v3 reader that occurred when a format-level key condition references a column that is not read from the Parquet file.Description
The Parquet v3 reader (
src/Processors/Formats/Impl/Parquet/Reader.cpp) maps each column used by the format-levelkey_conditionto a file-readable output column, so it can enable row-group min/max pruning for those columns. It threw aLOGICAL_ERROR("KeyCondition uses PREWHERE output") when the mapping was absent, on the assumption that the key condition only ever references columns read from the file. This logical error is a caught exception in release builds; it aborts the server only in debug and sanitizer builds.The
key_conditioncan reference a column that is not read from the file when that column appears only insideindexHintand the query reads no data column for it — for example an aggregate such asSELECT count()combined with both aPREWHERE indexHint(<cond on s>)and aWHERE indexHint(<cond on s>)on the same columns. The mapping to a file-readable output column is then absent and the reader throws the logical error. This reproduces with plain client SQL under the old analyzer (enable_analyzer = 0); the new (default) analyzer maps the column and is unaffected. Thematchwith a non-constant pattern in the original fuzzer query is incidental — a plainindexHint(s = 'x')reproduces it just as well.Fix: a key-condition column with no file-readable output column has no column-chunk or page-index statistics, so it cannot participate in pruning. Skip it at both pruning sites that map key-condition columns to file outputs: the row-group loop (leave its range as the whole universe, exactly as the reader already does for a column whose min/max statistics are missing) and the page-index loop right after it (
extractSingleColumnConditions, active by default viainput_format_parquet_page_filter_push_down), which otherwise threwLOGICAL_ERROR "Column condition uses PREWHERE output"on the identical unmapped column. A query that would otherwise succeed keeps returning correct, unpruned results, and the logical error is removed.Observed on
AST fuzzer (amd_debug, targeted)runs of two independent Parquet-v3-reader PRs (#106952 and #102499); never on master in 90 days.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106952&sha=80f44a37c823b1f13a3655214db9cbe9bc66a934&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29
A stateless test is added (
tests/queries/0_stateless/04498_parquet_key_condition_prewhere_output). It exercises the crash with plain client SQL underenable_analyzer = 0. Verified against the CI debug builds: it aborts on master HEAD (SIGABRT,Logical error: 'KeyCondition uses PREWHERE output'atReader.cpp:370) and passes on this PR, so per-arch Bugfix validation validates the fix.Version info
26.7.1.1331(included in26.7and later)