Repository navigation
Cherry pick #131371 to 26.10: Read the column that is smallest on disk when a MergeTree read needs no column - #131655
Conversation
…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
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.
|
I resolved the conflict and pushed the result to my fork (I cannot push to
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 |
|
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. |
|
🕵 I fast-forwarded The caveat above still holds: this brings the #131530 regression to 26.10, and its fix #131671 is still open. That PR is labeled |
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job