diff --git a/core/mvcc/cursor.rs b/core/mvcc/cursor.rs index 5e85b64f5..ad0f0e9e7 100644 --- a/core/mvcc/cursor.rs +++ b/core/mvcc/cursor.rs @@ -68,7 +68,6 @@ impl MvccLazyCursor { "BTreeCursor expected for mvcc cursor" ); let table_id = db.get_table_id_from_root_page(root_page_or_table_id); - println!("new MvccLazyCursor for table_id: {:?}", table_id); Ok(Self { db, tx_id, @@ -177,7 +176,7 @@ impl MvccLazyCursor { new_position_in_mvcc: &Option, current_rowid_in_btree: &Option, ) -> CursorPosition { - let new_position = match (new_position_in_mvcc, current_rowid_in_btree) { + match (new_position_in_mvcc, current_rowid_in_btree) { (Some(mvcc_rowid), Some(btree_rowid)) => { if mvcc_rowid < btree_rowid { CursorPosition::Loaded { @@ -216,8 +215,7 @@ impl MvccLazyCursor { btree_consumed: true, }, (None, None) => CursorPosition::End, - }; - new_position + } } fn is_btree_allocated(&self) -> bool { @@ -320,10 +318,8 @@ impl CursorTrait for MvccLazyCursor { CursorPosition::BeforeFirst => true, CursorPosition::End => true, }; - println!("current_pos: {:?}", self.get_current_pos()); let found = if self.is_btree_allocated() { - println!("btree_consumed: {:?}", btree_consumed); // If we have a functional btree, let's either find next value, or use the one pointed at by the cursor. if btree_consumed { return_if_io!(self.btree_cursor.next()) @@ -345,7 +341,6 @@ impl CursorTrait for MvccLazyCursor { CursorPosition::BeforeFirst => None, CursorPosition::End => None, }; - println!("found: {:?}", found); let current_rowid_in_btree = if found { let IOResult::Done(Some(rowid)) = self.btree_cursor.rowid()? else { panic!("BTree should have returned rowid after next"); @@ -355,26 +350,20 @@ impl CursorTrait for MvccLazyCursor { } else { // if the row is not valid, we need to continue to the next rowid in btree. // We first set consumed to true so that next time we call next, we don't use the same rowid. - match &mut *self.current_pos.borrow_mut() { - CursorPosition::Loaded { btree_consumed, .. } => { - *btree_consumed = true; - } - _ => {} + if let CursorPosition::Loaded { btree_consumed, .. } = + &mut *self.current_pos.borrow_mut() + { + *btree_consumed = true; } continue; } } else { None }; - println!( - "new_position_in_mvcc: {:?}, current_rowid_in_btree: {:?}", - new_position_in_mvcc, current_rowid_in_btree - ); let new_position = self.get_new_position_from_mvcc_and_btree( &new_position_in_mvcc, ¤t_rowid_in_btree, ); - println!("next new_position: {:?}", new_position); self.current_pos.replace(new_position); self.invalidate_record(); self.state.replace(None); @@ -604,19 +593,10 @@ impl CursorTrait for MvccLazyCursor { let IOResult::Done(maybe_rowid_in_btree) = self.btree_cursor.rowid()? else { panic!("BTree should have returned rowid after next"); }; - let maybe_rowid_in_btree = match maybe_rowid_in_btree { - Some(rowid) => { - if self.query_btree_version_is_valid(rowid) { - Some(rowid) - } else { - None - } - } - None => None, - }; + let maybe_rowid_in_btree = + maybe_rowid_in_btree.filter(|rowid| self.query_btree_version_is_valid(*rowid)); let new_position = self.get_new_position_from_mvcc_and_btree(&new_position_in_mvcc, &maybe_rowid_in_btree); - println!("rewind new_position: {:?}", new_position); self.current_pos.replace(new_position); Ok(IOResult::Done(())) } diff --git a/core/mvcc/database/mod.rs b/core/mvcc/database/mod.rs index 7f6981ebf..2e99ab260 100644 --- a/core/mvcc/database/mod.rs +++ b/core/mvcc/database/mod.rs @@ -28,7 +28,6 @@ use crate::{Connection, Pager}; use crossbeam_skiplist::{SkipMap, SkipSet}; use parking_lot::RwLock; use std::cell::RefCell; -use std::collections::HashSet; use std::fmt::Debug; use std::marker::PhantomData; use std::ops::Bound; @@ -1314,10 +1313,7 @@ impl MvStore { let tx = self.txs.get(&tx_id).unwrap(); let tx = tx.value(); - let versions = self.rows.get(&RowID { - table_id, - row_id: row_id, - }); + let versions = self.rows.get(&RowID { table_id, row_id }); if versions.is_none() { return RowVersionState::NotFound; } @@ -1325,9 +1321,9 @@ impl MvStore { let versions = versions.value().read(); let last_version = versions.last().unwrap(); if last_version.is_visible_to(tx, &self.txs) { - return RowVersionState::LiveVersion; + RowVersionState::LiveVersion } else { - return RowVersionState::Deleted; + RowVersionState::Deleted } } @@ -1348,23 +1344,6 @@ impl MvStore { .map(|_| *row.key()) } - fn find_last_visible_version_with_deleted( - &self, - tx: &Transaction, - row: crossbeam_skiplist::map::Entry< - '_, - RowID, - parking_lot::lock_api::RwLock>, - >, - ) -> Option { - row.value() - .read() - .iter() - .rev() - .find(|version| version.is_visible_to(tx, &self.txs)) - .map(|_| *row.key()) - } - pub fn seek_rowid( &self, bound: Bound<&RowID>,