Skip to content

Cherry pick #124468 to 26.9: Support virtual rows in reading in order with FINAL - #128663

Merged
robot-clickhouse merged 18 commits into
backport/26.9/124468from
cherrypick/26.9/124468
Nov 2, 2026
Merged

robot-clickhouse merged 18 commits into
backport/26.9/124468from
cherrypick/26.9/124468

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #124468

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

vdimir and others added 17 commits October 9, 2026 15:42
Reading in order through an `INNER JOIN` requires a virtual row, and a
`FINAL` read refused to build one, so such queries read and sorted the
whole left table. The FINAL merges still do not consume virtual rows: a
`VirtualRowTransform` after each of them announces the least primary key
its parts start from, taken from the primary index (the greatest for a
read in the reverse order), so the merge downstream defers the FINAL
merges the limit does not reach. The virtual row covers the primary key
prefix the sort reads, which is all the merge downstream compares, so the
other sorting key columns do not matter. Excluded: `GraphiteMergeTree`,
whose rollup lowers the time column, and parallel replicas.

The virtual rows are attached only when a step requested reading in
order, since a FINAL read is in order for its merges anyway, and the
optimizer drops the conversions when `requestReadingInOrder` refuses the
request.

The test 04489_virtual_row_disabled_with_final pinned the old refusal and
is removed; 03928 pins `read_in_order_use_virtual_row`, which its
reference now depends on.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A layer's virtual row was the least index value at its parts' range starts.
That bounds the layer loosely: the first granule of a sparse part may span
many keys, so the announced key sat far below the layer's start (205k keys
below for the second layer of the `final_read_in_order_limit` perf table,
whose update parts have gaps between their key blocks). The merge downstream
then left the front layer after a few hundred rows, armed its read-ahead
window and read every layer, so `WHERE v = 7 ORDER BY k LIMIT 100` read
8.1M rows with virtual rows against 9.3M without and got 25% slower.

`splitPartsWithRangesByPrimaryKey` now returns the layer borders, and
`spreadMarkRangesAmongStreamsFinal` takes the tighter of the parts' bound and
the border a layer starts from: `borders[i - 1]` for a forward read,
`borders[i]` for a reverse one. The same query now reads 426k rows from a
single layer and is 8% faster than without virtual rows.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Master moved `stringToBool` with its `CANNOT_PARSE_BOOL` declaration to
`SettingsFieldsConversionHelpers.cpp`, while `SettingFieldTriBool::readBinary`
in this branch still throws `CANNOT_PARSE_BOOL`. The style check on the merged
tree reported the code as used but not declared:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124468&sha=be990d897a35d190f6fc586accb7a7036ea311d9&name_0=PR&name_1=Style%20check
#124468

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Support virtual rows in reading in order with FINAL
@robot-clickhouse robot-clickhouse 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 2, 2026
@robot-clickhouse
robot-clickhouse merged commit 71ae220 into backport/26.9/124468 Nov 2, 2026
1 check passed
@robot-clickhouse
robot-clickhouse deleted the cherrypick/26.9/124468 branch November 2, 2026 14:43
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.

3 participants