Skip to content

Commit d4bfb9a

Browse files
authored
ScanIterByColRange: Avoid unnecessary ProductValue allocations (#804)
Prior to this commit, `ScanIterByColRange::next` called `RowRef::to_product_value` and then `ProductValue::project_not_empty` on every row in the table to get a key, which it compared to the sought range. This always allocated at least a `ProductValue`, even when seeking a range of primitive type like `u64`. It also unnecessarily deserialized (and potentially allocated) columns not relevant to the search for rows which did not match the range. With this commit, we call `RowRef::project_not_empty` directly. When the sought range is a single column, this avoids allocating a `ProductValue`. Even when seeking a multi-column range, this avoids deserializing unrelated columns of non-matching rows. Non-indexed `IterByColEq` is always going to be slow, so this probably doesn't matter, but it's a trivial change.
1 parent faf8766 commit d4bfb9a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

crates/core/src/db/datastore/locking_tx_datastore/state_view.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,7 @@ impl<'a, R: RangeBounds<AlgebraicValue>> Iterator for ScanIterByColRange<'a, R>
490490
#[tracing::instrument(skip_all)]
491491
fn next(&mut self) -> Option<Self::Item> {
492492
for row_ref in &mut self.scan_iter {
493-
let row = row_ref.to_product_value();
494-
let value = row.project_not_empty(&self.cols).unwrap();
493+
let value = row_ref.project_not_empty(&self.cols).unwrap();
495494
if self.range.contains(&value) {
496495
return Some(row_ref);
497496
}

0 commit comments

Comments
 (0)