-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
246 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,61 @@ | ||
use anyhow::Result; | ||
|
||
use crate::{plan::IndexScanPlan, tuple::Tuple}; | ||
use crate::{common::RID, index::IndexManager, plan::IndexScanPlan, tuple::Tuple}; | ||
|
||
use super::ExecutorContext; | ||
|
||
pub struct IndexScanExecutor<'a> { | ||
pub plan: IndexScanPlan, | ||
pub executor_context: &'a ExecutorContext, | ||
pub index_id: i64, | ||
pub rids: Option<Vec<RID>>, | ||
pub cursor: usize, | ||
} | ||
|
||
impl IndexScanExecutor<'_> { | ||
pub fn init(&mut self) -> Result<()> { | ||
let index = self | ||
let mut index = self | ||
.executor_context | ||
.catalog | ||
.lock() | ||
.map_err(|_| anyhow::anyhow!("Catalog lock error"))? | ||
.get_index(self.index_id, self.executor_context.transaction_id)?; | ||
println!("Index: {:?}", index); | ||
index.set_schema(self.plan.table_schema.clone()); | ||
let index_manager = IndexManager::new( | ||
index, | ||
self.executor_context.catalog.clone(), | ||
self.executor_context.buffer_pool_manager.clone(), | ||
); | ||
let right_value = self | ||
.plan | ||
.binary_expression | ||
.right | ||
.eval(&vec![&Tuple::new(None, &[])], &vec![]) | ||
.map_err(|_| anyhow::anyhow!("eval error"))?; | ||
self.rids = index_manager.lookup(&right_value)?; | ||
Ok(()) | ||
} | ||
pub fn next(&mut self) -> Result<Option<Tuple>> { | ||
Ok(None) | ||
if let Some(rids) = &self.rids { | ||
if self.cursor >= rids.len() { | ||
return Ok(None); | ||
} | ||
let rid = rids[self.cursor]; | ||
self.cursor += 1; | ||
let page = self | ||
.executor_context | ||
.buffer_pool_manager | ||
.lock() | ||
.map_err(|_| anyhow::anyhow!("lock error"))? | ||
.fetch_page(rid.0)?; | ||
let tuple_data = page | ||
.read() | ||
.map_err(|_| anyhow::anyhow!("read error"))? | ||
.with_table_page(|table_page| table_page.get_tuple(rid.1 as usize)); | ||
let tuple = Tuple::new(None, &tuple_data); | ||
Ok(Some(tuple)) | ||
} else { | ||
Ok(None) | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.