Skip granules consumed by OFFSET when reading in order#106578
Open
raimannma wants to merge 1 commit into
Open
Conversation
When a MergeTree table is read in primary key order with an OFFSET, the leading granules entirely consumed by the offset are read, merged and then dropped by the downstream offset step. This adds a query-plan optimization that, for forward read-in-order, drops the leading granules whose exact total row count does not exceed the offset (when each is strictly separated in primary key space from the remaining data) and reduces the downstream offset by the number of rows skipped. Gated by the new setting query_plan_optimize_read_in_order_skip_offset (default enabled). Applied only when it is safe: no FINAL, PREWHERE, lightweight deletes / row policies, sampling or parallel replicas, and a safe ascending primary key. Closes: ClickHouse#92671
0affc21 to
65ce224
Compare
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.
Closes: #92671
When a
MergeTreetable is read in primary key order with anOFFSET, the leading granules entirely consumed by the offset are still read, merged and then dropped by the downstream offset step. This adds a query-plan optimization that drops those leading granules during reading and reduces the downstream offset accordingly. It is gated by the new settingquery_plan_optimize_read_in_order_skip_offset(enabled by default) and only applies when it is safe to do so (forward read-in-order, noFINAL/PREWHERE/lightweight deletes/row policies/sampling/parallel replicas, and a safe ascending primary key).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
When reading a
MergeTreetable in primary key order with anOFFSET, skip reading the leading granules entirely consumed by the offset.