Repository navigation
Parquet v3: never schedule a decode into a dropped prewhere output slot - #113956
Conversation
`RowSubgroup::output` is sized once per subgroup to `extended_sample_block.columns()`, whose tail slots hold columns needed only for PREWHERE and filter evaluation. After the last PREWHERE step, `applyPrewhere` pops those tail slots off and nothing re-grows the vector. `ReadManager::finishRowSubgroupStage` runs the PREWHERE steps as step indices 1..N and the main step LAST, as step 0, and `addTasksToReadColumns` selects columns by `first_step_to_calculate == step_idx`. So a primitive column left at `first_step_to_calculate == 0` whose `idx_in_output_block` lands in that tail is decoded after the shrink, and `row_subgroup.output.at(idx_in_output_block)` throws `std::out_of_range`. That propagates as `Logical error: 'std::exception. Code: 1001, type: std::out_of_range'` and aborts the server from the `ReadManager` task pool. `Reader::preparePrewhere` now marks any such column with the `SIZE_MAX` sentinel step index that `ReadManager` never matches, which is the same state the existing injected-`covering.bbox` suppression already produces. A column that is in the tail and unclaimed has no consumer by construction: the delivered chunk is built by index over `sample_block->columns()`, and every PREWHERE step input gets `first_step_to_calculate = steps.size() + 1`. So this removes wasted work rather than making wasted work harmless, and the truncation is left exactly as it was. The `idx_in_output_block < extended_sample_block.columns()` bound is load-bearing, not defensive. `PrimitiveColumnInfo::idx_in_output_block` defaults to `UINT64_MAX` and `SchemaConverter` guarantees resolution only with a `chassert`, which is a no-op outside debug and sanitizer builds. Without the bound an unresolved index would compare greater than `sample_block->columns()` and be suppressed silently in release, turning a would-be assert into wrong results. The invariant is over the reader's own scheduling state rather than any query result, and no SQL query is known to reach the state: 979 observations across the parquet corpus and 28 targeted query shapes all left the tail empty of step-0 columns, and the input that produces it in CI is not identified. A query test written today would therefore pass unfixed, so the committed witness is a gtest asserting the three post-`preparePrewhere` values directly: the tail-and-unclaimed column is sentinelled, a claimed PREWHERE input keeps its step index, and an in-`sample_block` column stays at step 0. Related: ClickHouse#113841
…test The carrier query is identified, so the fix now ships a stateless test instead of resting on the gtest alone. Recovered from `clickhouse-server.err.log` of all four CI occurrences (that artifact is served for each of them; only `clickhouse-server.log` is not): the AST fuzzer bolts a PREWHERE that reads no file column onto a hive-partitioning query whose WHERE tests a partition column. Three of the four use a bare constant, one a column-free scalar subquery. An earlier version of this branch claimed the state was not reachable from SQL, citing 979 corpus observations and 28 query shapes. That sweep varied the PREWHERE column; the trigger needs a PREWHERE with no column at all, so `FormatFilterInfo`'s `!keys.has(col.name)` guard never pulls the WHERE column into `sample_block`. With `use_hive_partitioning = 1` a single local file reproduces it deterministically, and `04828_parquet_prewhere_hive_partition_column` aborts the server at the merge base and passes with the fix. Also guard the gtest with `#if USE_PARQUET`. `src/CMakeLists.txt` collects gtest sources with an unconditional `GLOB_RECURSE`, but the include dirs that resolve `generated/parquet_types.h` arrive only with `ch_contrib::parquet`. loongarch64 forces `ENABLE_PARQUET=OFF` while still building `clickhouse-bundle` with tests, so the unguarded translation unit broke that build. Related: ClickHouse#113841
Internal second-model review (click to expand)An independent cold review plus a second model reviewed this change against the ClickHouse review
Also verified independently during review: the three conjuncts of the new predicate are each pinned |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260808-094502 |
|
cc @grantholly-clickhouse @al13n321, could you review this? |
|
Workflow [PR], commit [1af1cac] Summary: ✅
AI ReviewSummaryThis PR fixes a real Parquet v3 scheduling bug in Missing context / blind spots
Final Verdict✅ No new inline findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 48/48 (100.00%) · Uncovered code |
CI finish ledger - f9a61d1Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
None of the three reds is PR-caused: this PR touches only the Parquet v3 reader Session id: cron:our-pr-ci-monitor:20260809-033000 |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 20 s compile time in total, 7 of them have a recent master baseline. |
|
🕵 Investigated the current |
|
🕵 Merged current |
|
Investigated separately. It does recur, and it is already owned. Recurrence: 4 hits in 30 days, all The STID does not identify a mechanism here. The carrier shape does discriminate. All four That shape is already tracked with an open fix, #113242 ("Do not push sorting into Merge children across an order-breaking cast"): I have attributed these four carriers there rather than opening anything new. What I have not proven: I could not reproduce under |
CI finish ledger for 1af1cacFull CI run completed with no failures: 164 checks succeeded, 17 skipped, 0 failed.
Note the three failures ledgered for the previous head Session id: cron:our-pr-ci-monitor:20260816-200000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes a
std::out_of_rangeexception (Logical error: 'std::exception. Code: 1001, type: std::out_of_range', which also aborts the server in debug and sanitizer builds) in the Parquet v3 reader when a column needed only for filter evaluation was scheduled for decoding after its output slot had already been dropped.Description
Related: #113841
RowSubgroup::outputis sized once per subgroup toextended_sample_block.columns(); its tail slots hold columns needed only for PREWHERE and filter evaluation. After the last PREWHERE stepapplyPrewherepops those tail slots off, and nothing re-grows the vector.ReadManagerruns the PREWHERE steps as step indices 1..N and the main step last, as step 0, selecting columns byfirst_step_to_calculate == step_idx. A primitive column still atfirst_step_to_calculate == 0whoseidx_in_output_blocklands in that tail is therefore decoded after the shrink, androw_subgroup.output.at(idx_in_output_block)throwsstd::out_of_range, which fails the query and, in debug and sanitizer builds, aborts the server from the reader's task pool.Reader::preparePrewherenow marks such a column with theSIZE_MAXsentinel step index thatReadManagernever matches, the same state the existing injected-covering.bboxsuppression already produces. A tail-and-unclaimed column has no consumer by construction: the delivered chunk is indexed oversample_block->columns(), and every PREWHERE step input getssteps.size() + 1. The truncation itself is unchanged.The upper bound against
extended_sample_block.columns()is load-bearing:idx_in_output_blockdefaults toUINT64_MAXand is onlychassert-checked, so without it an unresolved index would be suppressed silently in release builds.A PREWHERE that reads no file column reaches this from SQL: with
use_hive_partitioning = 1, a WHERE on a hive partition column stays in the output tail because no PREWHERE step claims it.All four CI occurrences are the AST fuzzer producing that shape against
03203_hive_style_partitioning; the recovered query is in the amd_asan_ubsan master report. New test04828_parquet_prewhere_hive_partition_columncovers it; the gtest additionally pins the unresolved-index boundary, which no query can construct.Validation
Both directions, each arm on its own Build-ID-asserted binary. SQL: pre-fix
rc=13410/10 runs withstd::out_of_rangeindecodePrimitiveColumnand the CI stack frame-for-frame; with the fixrc=010/10 returning101, which equals both the no-PREWHERE count and the total row count. Throughclickhouse-test, the new test fails at the merge base (server dies, exit 134) and passes with the fix;--test-runs 50gives 50/50 and-j 8leaves no staging dirs.Mutation matrix, each arm its own asserted Build ID:
SIZE_MAXassertion for the tail columnsample_blockassertions;04515abortsrc=134,04342dies onprimitive_columns_remaining == 0first_step_to_calculate == 0test04342dies the same wayextended_sample_blockupper boundRegression: 273
parquet/geo/icebergstateless tests on both arms, compared asReason:-bucketed sets: 0 verdict changes, 0 reason changes, 0 only-in-fix failures. 200/200 verdict lines pass over 20 randomized runs of the 10 environment-independent geo and prewhere tests.Version info
26.8.1.1538(included in26.8and later)