Skip to content

Cherry pick #131371 to 26.10: Read the column that is smallest on disk when a MergeTree read needs no column - #131655

Merged
robot-ch-test-poll merged 4 commits into
backport/26.10/131371from
cherrypick/26.10/131371
Nov 18, 2026
Merged

robot-ch-test-poll merged 4 commits into
backport/26.10/131371from
cherrypick/26.10/131371

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

Original pull-request #131371

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 3 commits November 13, 2026 16:08
…no column

With `query_plan_remove_unused_columns = 1` (the default since 25.12), a
`MergeTree` read that needs no column of the table (`SELECT count()` that has
to scan, e.g. after a lightweight `DELETE`; `sum(1)`; `count()` over a
subquery; `count() ... FINAL`; a constant-folded `isNullable(c)`) read the
column with the smallest data type instead of the one smallest on disk.

The planner chooses the row-count column by its size on disk
(`chooseSmallestColumnToReadFromStorage`), but the plan-level column pruning
removes it from `ReadFromMergeTree` because nothing above uses it, and the
static `ReadFromMergeTree::selectRangesToRead` then re-adds a column with
`ExpressionActions::getSmallestColumn`, which ranks by
`getMaximumSizeOfValueInMemory` only: a `Nullable(UInt8)` of 118 MB beat a
sparse `Int32` of 1.5 KB on the table from #131235 (126 MB read instead of
91 KB). The same fallback causes #106597 (`isNullable(lc)` in the perf test
`low_cardinality_argument` reads `x`, 40 MB, instead of `lc`, 1.8 MB).

The <compressed size, type size, uncompressed size> ranking, written twice
(planner `ColumnWithSize`, `TreeRewriter` `ColumnSizeTuple`), becomes one
function, `ExpressionActions::getCheapestColumnToRead`, used by both of them
unchanged (same candidates, order, ties and fallback) and by
`selectRangesToRead` right before its normal return, from the table's cached
column sizes, when no column is needed and at least one non-projection part
is read. The early returns keep the type-ranked carrier and make no size
lookup (none of them reads a part through it), and projection parts keep it
too, because the table's column sizes do not describe them.

Closes #131235
Closes #106597

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the getCheapestColumnToRead header comment from three lines to two.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sk-column-when-no-column-is-needed

Read the column that is smallest on disk when a MergeTree read needs no column
@robot-ch-test-poll robot-ch-test-poll added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Nov 14, 2026
Resolve the conflict in src/Planner/PlannerJoinTree.cpp: keep the 26.10 side and take only the lines of #131371. The `skip_subcolumns` argument of the master call refers to `filtered_by_allowed_columns`, which comes from #103402 (not in 26.10), so the call uses the default, as the replaced `getSmallestColumn` call on 26.10 did.
@groeneai

Copy link
Copy Markdown
Collaborator

I resolved the conflict and pushed the result to my fork (I cannot push to cherrypick/*).

git fetch https://github.com/groeneai/ClickHouse groeneai/resolve-26.10-cherrypick-131371
git push origin FETCH_HEAD:cherrypick/26.10/131371

Caveat: #131371 has an open regression on master, #131530, and this backport brings it to 26.10. On this tree the reproducer from #131530 fails with TOO_MANY_BYTES (968.75 KiB read against a 97.66 KiB limit), while 26.10.5.10 returns 1001. Its fix is not merged yet; I will link its PR here when it opens, so both can reach 26.10 together.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix for #131530 is #131671.

@robot-clickhouse

Copy link
Copy Markdown
Member

Dear @alexey-milovidov, @groeneai, this cherry-pick PR has not been updated for 3d0h4m2s. Please resolve the conflicts to backport #131371, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 I fast-forwarded cherrypick/26.10/131371 to the resolution from @groeneai (e5422ff9bd2f, which merges backport/26.10/131371 into 82d74f671669). Against the backport branch, the diff touches only the 7 files of #131371. All four changed translation units pass a -fsyntax-only check on the 26.10 tree.

The caveat above still holds: this brings the #131530 regression to 26.10, and its fix #131671 is still open. That PR is labeled pr-bugfix and has no backport label yet. Decide whether to merge this backport before #131671 lands and is backported to 26.10.

@robot-ch-test-poll
robot-ch-test-poll merged commit d3e8549 into backport/26.10/131371 Nov 18, 2026
2 checks passed
@robot-ch-test-poll
robot-ch-test-poll deleted the cherrypick/26.10/131371 branch November 18, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants