Repository navigation
Cherry pick #124468 to 26.8: Support virtual rows in reading in order with FINAL - #128661
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-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