feat(storage): avoid copy key slice in storage table iter when unnecessary #19717
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.
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
Previously in the iter of
StorageTable
andStateTable
, we yieldKeyedRow
, which includes theTableKey<Bytes>
of the row. TheTableKey<Bytes>
is created by copying from a key slice yielded fromStateStoreIter
. Creating suchTableKey<Bytes>
involves memory allocation and slice clone, which may incur extra cost. However, in some cases, the key is discarded and not used, which makes the extra cost unnecessary. The key is used mostly for sorting the result of multiple iters, and when the key is not used, we don't have to create the key.Therefore, in this PR, we will try to avoid creating unnecessary keys. In
StorageTable
, the key is kept for doingmerge_sort
.merge_sort
is used only when specifiedordered = true
and having more than one vnodes. Therefore, whenmerge_sort
is not used, we change to return a stream that only yieldsOwnedRow
, and when usingmerge_sort
, we will include the key in the input ofmerge_sort
, and then discard the key in the output.The
iter_xxx
methods ofStorageTable
andStateTable
previously yield theKeyedRow
. In this PR, the items of these methods becomeOwnedRow
. Some streaming executors may still need theKeyedRow
for sorting, and therefore we provide an extraiter_keyed_row_with_prefix
as a counterpart toiter_with_prefix
and yieldKeyedRow
. So as is methods that calliter_log
.Checklist
./risedev check
(or alias,./risedev c
)Documentation
Release note
If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.