Skip to content

Backport #108977 to 26.3: Fix out-of-bounds crash in ObjectStorageQueueSource::FileIterator::next - #112983

Merged
kssenii merged 2 commits into
26.3from
backport/26.3/108977
Aug 4, 2026
Merged

kssenii merged 2 commits into
26.3from
backport/26.3/108977

Conversation

@robot-clickhouse-ci-1

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #108977
Cherry-pick pull-request #112835

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.3.17.107

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix labels Aug 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [d52bf80]

Summary: ✅

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112983&sha=f9a498a0192726beb574c24afad6a5159c2c2efa&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan%2C%20distributed%20plan%2C%20parallel%2C%202%2F2%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The only red here is 04408_lazy_materialization_part_offset_prewhere in Stateless tests (amd_asan, distributed plan, parallel, 2/2). It is unrelated to this backport, which only touches ObjectStorageQueue.

It is a pre-existing, 26.3-only failure. CI history for the last 30 days, restricted to the distributed plan job:

branch runs failures
master 671 0
26.7 45 0
26.6 50 0
26.5 77 0
26.4 32 0
26.3 29 8

So it fails on roughly 30% of 26.3 runs (including scheduled runs of the 26.3 branch itself, pull_request_number = 0) and never on master or any other release branch.

Query 28 fails with:

Code: 10. DB::Exception: Not found column Id: in block __global_row_index UInt64, _part_starting_offset UInt64, _part_offset UInt64, _part_offset UInt64. (NOT_FOUND_COLUMN_IN_BLOCK)
(in query: SELECT EventId FROM repro PREWHERE _part_offset < 100 ORDER BY Id DESC LIMIT 10;)

thrown from ActionsDAG::evaluatePartialResult via ExpressionStep construction inside QueryPlanOptimizations::optimizeLazyMaterialization2. Note the duplicated _part_offset in the block.

That is the test case added by #108287 (The bare virtual column is the row-level filter column and a PREWHERE expression input). The reexpose_in_filter part of that fix is present in 26.3 (src/Processors/QueryPlan/ReadFromMergeTree.cpp), and the .sql/.reference files are byte-identical to master, so the backport itself is not truncated. The lazy-materialization implementation on 26.3 has since diverged substantially from 26.4+ (optimizeLazyMaterialization.cpp differs by +227/-76 and ReadFromMergeTree.cpp by +236/-97 against 26.4), so the follow-up that makes this stable on the newer branches has no straightforward equivalent on 26.3.

There is no tracking issue for it yet, and no open or merged PR fixing it on 26.3.

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

No fix PR exists yet, on 26.3 or anywhere. I traced the root cause; it is not the #108287 backport.

The 26.3 gap is #96682 ("Properly remove unneeded columns for lazy materialization", commit a88e77e9a0d7338, merged 2026-04-08). Its containment matches the pass/fail split exactly:

branch contains a88e77e9? forked from master
master, 26.7, 26.6, 26.5, 26.4 yes (behind_by = 0) 26.4: 2026-04-21
26.3 no (diverged, behind_by = 1) 2026-03-19

26.3 is the only active branch that forked before that merge. Independently corroborated: that PR's own regression test 03814_lazy_materialization_unneded_columns_bug.sql is present on 26.4/26.5/master and absent (404) on 26.3.

Mechanism: #96682 replaced name-keyed column trimming with position-keyed bookkeeping. 26.3 still has removeUnusedColumnsFromReadingStep, which collects required columns into a NameSet; 26.4+ dropped it, and their splitFilterStep calls addRequiredInputDependenciesIntoNodesSet before ActionsDAG::split alongside mapInputsToHeaderPositions, which keeps a list<size_t> of header positions per name and pops one per input, so it can represent two header columns sharing a name. A NameSet cannot represent the duplicated _part_offset you spotted (one occurrence from the row policy USING _part_offset, one re-exposed by #108287), so the duplicate collapses and Id is dropped from the main half.

That also confirms the #108287 backport is correct and complete rather than ineffective: reexpose_in_filter is byte-identical on 26.3/26.4/master, and diffing the entire surrounding block of ReadFromMergeTree.cpp (26.3 L3200-3290 against 26.4 L3270-3360) gives no differences at all, as does calculateGlobalOffset. It is a missing prerequisite, not a truncated backport.

For completeness, hasInputNameShadowedByComputedNode (your 2b273b198ed3d17, #112326) is not the fix for this one: 26.4 through 26.7 are all clean without it.

One caveat that matters for the route. A v26.3-must-backport label on #96682 would produce a broken PR that looks clean. git apply of the patch onto the 26.3 file fails, but git merge-tree --write-tree --merge-base=a88e77e9^ 26.3 a88e77e9 returns 0 with tree 681ac6f4da88ce5 -- and in that tree the trimming call is left commented out, // auto lazy_reading = removeUnusedColumnsFromReadingStep(...), with nothing replacing it and lazy_reading never assigned. The FINAL-columns block that 26.4 added is missing too. So the automation would open a PR that merges cleanly and does not build.

I have not opened a 26.3 PR: per @ pufit's instruction I do not hand-author release-branch changes, which you confirmed on #111910. Given the above, the label route alone will not work here either, so could you say which you prefer:

  1. backport #96682 to 26.3 with the conflict hand-resolved by its author (@ KochetovNicolai), since the divergence is in the code he rewrote; or
  2. leave 26.3 on the older implementation and gate the optimization off for this plan shape there.

I am happy to do the legwork on either once you pick, and to open a tracking issue if you want one.

One thing I could not determine: which randomized setting selects the failing plan on roughly 30% of runs. --distributed-plan is an install argument rather than a query setting, so clickhouse local on the prebuilt 26.3 binary reproduces neither query 28 alone nor the full file, and a sweep over the lazy-materialization and prewhere settings did not flip it.

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

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants