Skip to content

Commit

Permalink
Use SchemaRef in IndexMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
lewiszlw committed Jan 29, 2024
1 parent 68914bb commit e7607f3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions bustubx/src/catalog/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ impl Catalog {
.get_table_by_name(&table_name)
.expect("table not found");
let tuple_schema = table_info.schema.clone();
let key_schema = Arc::new(Schema::copy_schema(&tuple_schema, &key_attrs));
let key_schema = Arc::new(Schema::copy_schema(tuple_schema.clone(), &key_attrs));

let index_metadata = IndexMetadata::new(
index_name.clone(),
table_name.clone(),
&tuple_schema,
tuple_schema.clone(),
key_attrs,
);
// one buffer pool manager for one index
Expand Down
2 changes: 1 addition & 1 deletion bustubx/src/catalog/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Schema {
Self { columns }
}

pub fn copy_schema(from: &Schema, key_attrs: &[u32]) -> Self {
pub fn copy_schema(from: SchemaRef, key_attrs: &[u32]) -> Self {
let columns = key_attrs
.iter()
.map(|i| from.columns[*i as usize].clone())
Expand Down
2 changes: 1 addition & 1 deletion bustubx/src/planner/physical_plan/create_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl PhysicalCreateIndex {
}
}
pub fn output_schema(&self) -> Schema {
Schema::copy_schema(&self.table_schema, &self.key_attrs)
Schema::copy_schema(self.table_schema.clone(), &self.key_attrs)
}
}
impl VolcanoExecutor for PhysicalCreateIndex {
Expand Down
20 changes: 11 additions & 9 deletions bustubx/src/storage/index.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::VecDeque;
use std::sync::Arc;

use crate::catalog::SchemaRef;
use crate::{
buffer::buffer_pool::BufferPoolManager,
catalog::Schema,
Expand All @@ -20,21 +22,21 @@ pub struct IndexMetadata {
pub table_name: String,
// key schema与tuple schema的映射关系
pub key_attrs: Vec<u32>,
pub key_schema: Schema,
pub key_schema: SchemaRef,
}
impl IndexMetadata {
pub fn new(
index_name: String,
table_name: String,
tuple_schema: &Schema,
tuple_schema: SchemaRef,
key_attrs: Vec<u32>,
) -> Self {
let key_schema = Schema::copy_schema(tuple_schema, &key_attrs);
Self {
index_name,
table_name,
key_attrs,
key_schema,
key_schema: Arc::new(key_schema),
}
}
}
Expand Down Expand Up @@ -776,12 +778,12 @@ mod tests {
let index_metadata = IndexMetadata::new(
"test_index".to_string(),
"test_table".to_string(),
&Schema::new(vec![
Arc::new(Schema::new(vec![
Column::new("a".to_string(), DataType::Int8),
Column::new("b".to_string(), DataType::Int16),
Column::new("c".to_string(), DataType::Int8),
Column::new("d".to_string(), DataType::Int16),
]),
])),
vec![1, 3],
);
assert_eq!(index_metadata.key_schema.column_count(), 2);
Expand All @@ -803,10 +805,10 @@ mod tests {
let index_metadata = IndexMetadata::new(
"test_index".to_string(),
"test_table".to_string(),
&Schema::new(vec![
Arc::new(Schema::new(vec![
Column::new("a".to_string(), DataType::Int8),
Column::new("b".to_string(), DataType::Int16),
]),
])),
vec![0, 1],
);
let disk_manager = DiskManager::try_new(&temp_path).unwrap();
Expand Down Expand Up @@ -862,10 +864,10 @@ mod tests {
let index_metadata = IndexMetadata::new(
"test_index".to_string(),
"test_table".to_string(),
&Schema::new(vec![
Arc::new(Schema::new(vec![
Column::new("a".to_string(), DataType::Int8),
Column::new("b".to_string(), DataType::Int16),
]),
])),
vec![0, 1],
);
let disk_manager = DiskManager::try_new(&temp_path).unwrap();
Expand Down

0 comments on commit e7607f3

Please sign in to comment.