mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 17:05:36 +01:00
chore: fix clippy
This commit is contained in:
@@ -1449,287 +1449,6 @@ impl BTreeCursor {
|
||||
}
|
||||
}
|
||||
|
||||
/// Specialized version of move_to() for index btrees.
|
||||
// #[instrument(skip(self, index_key), level = Level::TRACE)]
|
||||
// fn indexbtree_move_to(
|
||||
// &mut self,
|
||||
// index_key: &ImmutableRecord,
|
||||
// cmp: SeekOp,
|
||||
// ) -> Result<CursorResult<()>> {
|
||||
// let iter_dir = cmp.iteration_direction();
|
||||
|
||||
// let key_values = index_key.get_values();
|
||||
// let index_info = &self.index_key_info.unwrap();
|
||||
// let record_comparer = find_compare(&key_values, &index_info, &self.collations);
|
||||
// println!("record_comparer: {:?}", record_comparer);
|
||||
// tracing::debug!("Using record comparison strategy: {:?}", record_comparer);
|
||||
|
||||
// 'outer: loop {
|
||||
// let page = self.stack.top();
|
||||
// return_if_locked_maybe_load!(self.pager, page);
|
||||
// let page = page.get();
|
||||
// let contents = page.get().contents.as_ref().unwrap();
|
||||
// if contents.is_leaf() {
|
||||
// let eq_seen = match &self.seek_state {
|
||||
// CursorSeekState::MovingBetweenPages { eq_seen } => eq_seen.get(),
|
||||
// _ => false,
|
||||
// };
|
||||
// self.seek_state = CursorSeekState::FoundLeaf {
|
||||
// eq_seen: Cell::new(eq_seen),
|
||||
// };
|
||||
// return Ok(CursorResult::Ok(()));
|
||||
// }
|
||||
|
||||
// if matches!(
|
||||
// self.seek_state,
|
||||
// CursorSeekState::Start | CursorSeekState::MovingBetweenPages { .. }
|
||||
// ) {
|
||||
// let eq_seen = match &self.seek_state {
|
||||
// CursorSeekState::MovingBetweenPages { eq_seen } => eq_seen.get(),
|
||||
// _ => false,
|
||||
// };
|
||||
// let cell_count = contents.cell_count();
|
||||
// let min_cell_idx = Cell::new(0);
|
||||
// let max_cell_idx = Cell::new(cell_count as isize - 1);
|
||||
// let nearest_matching_cell = Cell::new(None);
|
||||
|
||||
// self.seek_state = CursorSeekState::InteriorPageBinarySearch {
|
||||
// min_cell_idx,
|
||||
// max_cell_idx,
|
||||
// nearest_matching_cell,
|
||||
// eq_seen: Cell::new(eq_seen),
|
||||
// };
|
||||
// }
|
||||
|
||||
// let CursorSeekState::InteriorPageBinarySearch {
|
||||
// min_cell_idx,
|
||||
// max_cell_idx,
|
||||
// nearest_matching_cell,
|
||||
// eq_seen,
|
||||
// } = &self.seek_state
|
||||
// else {
|
||||
// unreachable!(
|
||||
// "we must be in an interior binary search state, got {:?}",
|
||||
// self.seek_state
|
||||
// );
|
||||
// };
|
||||
|
||||
// loop {
|
||||
// let min = min_cell_idx.get();
|
||||
// let max = max_cell_idx.get();
|
||||
// if min > max {
|
||||
// let Some(leftmost_matching_cell) = nearest_matching_cell.get() else {
|
||||
// self.stack.set_cell_index(contents.cell_count() as i32 + 1);
|
||||
// match contents.rightmost_pointer() {
|
||||
// Some(right_most_pointer) => {
|
||||
// let mem_page = self.read_page(right_most_pointer as usize)?;
|
||||
// self.stack.push(mem_page);
|
||||
// self.seek_state = CursorSeekState::MovingBetweenPages {
|
||||
// eq_seen: Cell::new(eq_seen.get()),
|
||||
// };
|
||||
// continue 'outer;
|
||||
// }
|
||||
// None => {
|
||||
// unreachable!(
|
||||
// "we shall not go back up! The only way is down the slope"
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// let matching_cell = contents.cell_get(
|
||||
// leftmost_matching_cell,
|
||||
// payload_overflow_threshold_max(
|
||||
// contents.page_type(),
|
||||
// self.usable_space() as u16,
|
||||
// ),
|
||||
// payload_overflow_threshold_min(
|
||||
// contents.page_type(),
|
||||
// self.usable_space() as u16,
|
||||
// ),
|
||||
// self.usable_space(),
|
||||
// )?;
|
||||
// self.stack.set_cell_index(leftmost_matching_cell as i32);
|
||||
// // we don't advance in case of forward iteration and index tree internal nodes because we will visit this node going up.
|
||||
// // in backwards iteration, we must retreat because otherwise we would unnecessarily visit this node again.
|
||||
// // Example:
|
||||
// // this parent: key 666, and we found the target key in the left child.
|
||||
// // left child has: key 663, key 664, key 665
|
||||
// // we need to move to the previous parent (with e.g. key 662) when iterating backwards so that we don't end up back here again.
|
||||
// if iter_dir == IterationDirection::Backwards {
|
||||
// self.stack.retreat();
|
||||
// }
|
||||
// let BTreeCell::IndexInteriorCell(IndexInteriorCell {
|
||||
// left_child_page, ..
|
||||
// }) = &matching_cell
|
||||
// else {
|
||||
// unreachable!("unexpected cell type: {:?}", matching_cell);
|
||||
// };
|
||||
|
||||
// let mem_page = self.read_page(*left_child_page as usize)?;
|
||||
// self.stack.push(mem_page);
|
||||
// self.seek_state = CursorSeekState::MovingBetweenPages {
|
||||
// eq_seen: Cell::new(eq_seen.get()),
|
||||
// };
|
||||
// continue 'outer;
|
||||
// }
|
||||
|
||||
// let cur_cell_idx = (min + max) >> 1; // rustc generates extra insns for (min+max)/2 due to them being isize. we know min&max are >=0 here.
|
||||
// self.stack.set_cell_index(cur_cell_idx as i32);
|
||||
// let cell = contents.cell_get(
|
||||
// cur_cell_idx as usize,
|
||||
// payload_overflow_threshold_max(
|
||||
// contents.page_type(),
|
||||
// self.usable_space() as u16,
|
||||
// ),
|
||||
// payload_overflow_threshold_min(
|
||||
// contents.page_type(),
|
||||
// self.usable_space() as u16,
|
||||
// ),
|
||||
// self.usable_space(),
|
||||
// )?;
|
||||
// let BTreeCell::IndexInteriorCell(IndexInteriorCell {
|
||||
// payload,
|
||||
// payload_size,
|
||||
// first_overflow_page,
|
||||
// ..
|
||||
// }) = &cell
|
||||
// else {
|
||||
// unreachable!("unexpected cell type: {:?}", cell);
|
||||
// };
|
||||
|
||||
// if let Some(next_page) = first_overflow_page {
|
||||
// return_if_io!(self.process_overflow_read(payload, *next_page, *payload_size))
|
||||
// } else {
|
||||
// self.get_immutable_record_or_create()
|
||||
// .as_mut()
|
||||
// .unwrap()
|
||||
// .start_serialization(payload);
|
||||
// self.record_cursor.borrow_mut().invalidate();
|
||||
// };
|
||||
// let (target_leaf_page_is_in_left_subtree, is_eq) = {
|
||||
// let record = self.get_immutable_record();
|
||||
// let record = record.as_ref().unwrap();
|
||||
|
||||
// // DEBUG COMPARISON - Compare old vs new method
|
||||
// let old_cmp = {
|
||||
// let record_values = record.get_values();
|
||||
// let record_slice_equal_number_of_cols = &record_values[..key_values.len()];
|
||||
// compare_immutable(
|
||||
// record_slice_equal_number_of_cols,
|
||||
// key_values.as_slice(),
|
||||
// self.key_sort_order(),
|
||||
// &self.collations,
|
||||
// )
|
||||
// };
|
||||
|
||||
// let new_cmp = match record_comparer.compare(
|
||||
// record,
|
||||
// &key_values,
|
||||
// &index_info,
|
||||
// &self.collations,
|
||||
// 0,
|
||||
// ) {
|
||||
// Ok(ordering) => ordering,
|
||||
// Err(e) => {
|
||||
// println!("Optimized record comparison failed: {:?}", e);
|
||||
// match compare_records_generic(
|
||||
// record,
|
||||
// &key_values,
|
||||
// &index_info,
|
||||
// &self.collations,
|
||||
// 0,
|
||||
// ) {
|
||||
// Ok(ordering) => {
|
||||
// println!("Generic comparison succeeded where optimized failed");
|
||||
// ordering
|
||||
// }
|
||||
// Err(fallback_err) => {
|
||||
// println!("Generic comparison also failed: {:?}", fallback_err);
|
||||
// old_cmp // Use old comparison as final fallback
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
// println!("old_cmp: {:?}, new_cmp: {:?}", old_cmp, new_cmp);
|
||||
|
||||
// // Check for mismatches
|
||||
// if old_cmp != new_cmp {
|
||||
// println!(
|
||||
// "COMPARISON MISMATCH in indexbtree_move_to! Old: {:?}, New: {:?}, Strategy: {:?}",
|
||||
// old_cmp, new_cmp, record_comparer);
|
||||
|
||||
// let record_values = record.get_values();
|
||||
// println!(
|
||||
// "Record values: {:?}, Key values: {:?}, Index info: {:?}",
|
||||
// record_values, key_values, index_info
|
||||
// );
|
||||
|
||||
// // Use old comparison for correctness while debugging
|
||||
// let interior_cell_vs_index_key = old_cmp;
|
||||
// } else {
|
||||
// // Use new comparison if they match
|
||||
// let interior_cell_vs_index_key = new_cmp;
|
||||
// }
|
||||
|
||||
// let interior_cell_vs_index_key =
|
||||
// if old_cmp != new_cmp { old_cmp } else { new_cmp };
|
||||
|
||||
// // in sqlite btrees left child pages have <= keys.
|
||||
// // in general, in forwards iteration we want to find the first key that matches the seek condition.
|
||||
// // in backwards iteration we want to find the last key that matches the seek condition.
|
||||
// //
|
||||
// // Logic table for determining if target leaf page is in left subtree.
|
||||
// // For index b-trees this is a bit more complicated since the interior cells contain payloads (the key is the payload).
|
||||
// // and for non-unique indexes there might be several cells with the same key.
|
||||
// //
|
||||
// // Forwards iteration (looking for first match in tree):
|
||||
// // OP | Current Cell vs Seek Key | Action? | Explanation
|
||||
// // GT | > | go left | First > key could be exactly this one, or in left subtree
|
||||
// // GT | = or < | go right | First > key must be in right subtree
|
||||
// // GE | > | go left | First >= key could be exactly this one, or in left subtree
|
||||
// // GE | = | go left | First >= key could be exactly this one, or in left subtree
|
||||
// // GE | < | go right | First >= key must be in right subtree
|
||||
// //
|
||||
// // Backwards iteration (looking for last match in tree):
|
||||
// // OP | Current Cell vs Seek Key | Action? | Explanation
|
||||
// // LE | > | go left | Last <= key must be in left subtree
|
||||
// // LE | = | go right | Last <= key is either this one, or somewhere to the right of this one. So we need to go right to make sure
|
||||
// // LE | < | go right | Last <= key must be in right subtree
|
||||
// // LT | > | go left | Last < key must be in left subtree
|
||||
// // LT | = | go left | Last < key must be in left subtree since we want strictly less than
|
||||
// // LT | < | go right | Last < key could be exactly this one, or in right subtree
|
||||
// //
|
||||
// // No iteration (point query):
|
||||
// // EQ | > | go left | First = key must be in left subtree
|
||||
// // EQ | = | go left | First = key could be exactly this one, or in left subtree
|
||||
// // EQ | < | go right | First = key must be in right subtree
|
||||
|
||||
// (
|
||||
// match cmp {
|
||||
// SeekOp::GT => interior_cell_vs_index_key.is_gt(),
|
||||
// SeekOp::GE { .. } => interior_cell_vs_index_key.is_ge(),
|
||||
// SeekOp::LE { .. } => interior_cell_vs_index_key.is_gt(),
|
||||
// SeekOp::LT => interior_cell_vs_index_key.is_ge(),
|
||||
// },
|
||||
// interior_cell_vs_index_key.is_eq(),
|
||||
// )
|
||||
// };
|
||||
|
||||
// if is_eq {
|
||||
// eq_seen.set(true);
|
||||
// }
|
||||
|
||||
// if target_leaf_page_is_in_left_subtree {
|
||||
// nearest_matching_cell.set(Some(cur_cell_idx as usize));
|
||||
// max_cell_idx.set(cur_cell_idx - 1);
|
||||
// } else {
|
||||
// min_cell_idx.set(cur_cell_idx + 1);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/// Specialized version of move_to() for index btrees.
|
||||
#[instrument(skip(self, index_key), level = Level::INFO)]
|
||||
fn indexbtree_move_to(
|
||||
|
||||
@@ -1052,50 +1052,6 @@ impl<T: Default + Copy, const N: usize> Iterator for SmallVecIter<'_, T, N> {
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn read_record(payload: &[u8], reuse_immutable: &mut ImmutableRecord) -> Result<()> {
|
||||
// // Let's clear previous use
|
||||
// reuse_immutable.invalidate();
|
||||
// // Copy payload to ImmutableRecord in order to make RefValue that point to this new buffer.
|
||||
// // By reusing this immutable record we make it less allocation expensive.
|
||||
// reuse_immutable.start_serialization(payload);
|
||||
|
||||
// let mut pos = 0;
|
||||
// let (header_size, nr) = read_varint(payload)?;
|
||||
// assert!((header_size as usize) >= nr);
|
||||
// let mut header_size = (header_size as usize) - nr;
|
||||
// pos += nr;
|
||||
|
||||
// let mut serial_types = SmallVec::<u64, 64>::new();
|
||||
// while header_size > 0 {
|
||||
// let (serial_type, nr) = read_varint(&reuse_immutable.get_payload()[pos..])?;
|
||||
// validate_serial_type(serial_type)?;
|
||||
// serial_types.push(serial_type);
|
||||
// pos += nr;
|
||||
// assert!(header_size >= nr);
|
||||
// header_size -= nr;
|
||||
// }
|
||||
|
||||
// for &serial_type in &serial_types.data[..serial_types.len.min(serial_types.data.len())] {
|
||||
// let (value, n) = read_value(&reuse_immutable.get_payload()[pos..], unsafe {
|
||||
// serial_type.assume_init().try_into()?
|
||||
// })?;
|
||||
// pos += n;
|
||||
// reuse_immutable.add_value(value);
|
||||
// }
|
||||
// if let Some(extra) = serial_types.extra_data.as_ref() {
|
||||
// for serial_type in extra {
|
||||
// let (value, n) = read_value(
|
||||
// &reuse_immutable.get_payload()[pos..],
|
||||
// (*serial_type).try_into()?,
|
||||
// )?;
|
||||
// pos += n;
|
||||
// reuse_immutable.add_value(value);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
/// Reads a value that might reference the buffer it is reading from. Be sure to store RefValue with the buffer
|
||||
/// always.
|
||||
#[inline(always)]
|
||||
|
||||
Reference in New Issue
Block a user