From a35408f425f6bd7ebddb74f8c5c493e789caf8e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9E=97=E4=BC=9F?= Date: Wed, 28 Feb 2024 11:10:56 +0800 Subject: [PATCH] Fix table loading --- bustubx/src/catalog/catalog.rs | 1 - bustubx/src/catalog/information.rs | 21 ++++----------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/bustubx/src/catalog/catalog.rs b/bustubx/src/catalog/catalog.rs index 145a995..b162060 100644 --- a/bustubx/src/catalog/catalog.rs +++ b/bustubx/src/catalog/catalog.rs @@ -160,7 +160,6 @@ impl Catalog { catalog_schema_name.clone().into(), table_name.clone().into(), (table_heap.first_page_id.load(Ordering::SeqCst)).into(), - (table_heap.last_page_id.load(Ordering::SeqCst)).into(), ], ); tables_table.table.insert_tuple(&EMPTY_TUPLE_META, &tuple)?; diff --git a/bustubx/src/catalog/information.rs b/bustubx/src/catalog/information.rs index 897fe4d..274f7c1 100644 --- a/bustubx/src/catalog/information.rs +++ b/bustubx/src/catalog/information.rs @@ -26,15 +26,8 @@ lazy_static::lazy_static! { Column::new("table_schema", DataType::Varchar(None), false), Column::new("table_name", DataType::Varchar(None), false), Column::new("first_page_id", DataType::UInt32, false), - Column::new("last_page_id", DataType::UInt32, false), ])); - pub static ref TABLES_TABLE_REF: TableReference = TableReference::full( - DEFAULT_CATALOG_NAME, - INFORMATION_SCHEMA_NAME, - INFORMATION_SCHEMA_TABLES, - ); - pub static ref COLUMNS_SCHMEA: SchemaRef = Arc::new(Schema::new(vec![ Column::new("table_catalog", DataType::Varchar(None), false), Column::new("table_schema", DataType::Varchar(None), false), @@ -43,12 +36,6 @@ lazy_static::lazy_static! { Column::new("data_type", DataType::Varchar(None), false), Column::new("nullable", DataType::Boolean, false), ])); - - pub static ref COLUMNS_TABLE_REF: TableReference = TableReference::full( - DEFAULT_CATALOG_NAME, - INFORMATION_SCHEMA_NAME, - INFORMATION_SCHEMA_COLUMNS, - ); } pub fn load_catalog_data(db: &mut Database) -> BustubxResult<()> { @@ -173,9 +160,6 @@ fn load_user_tables(db: &mut Database) -> BustubxResult<()> { let ScalarValue::UInt32(Some(first_page_id)) = table_tuple.value(3)? else { return error; }; - let ScalarValue::UInt32(Some(last_page_id)) = table_tuple.value(4)? else { - return error; - }; let column_tuples = db.run(&format!("select * from {}.{} where table_catalog = '{}' and table_schema = '{}' and table_name = '{}'", INFORMATION_SCHEMA_NAME, INFORMATION_SCHEMA_COLUMNS, catalog, table_schema, table_name))?; @@ -199,11 +183,14 @@ fn load_user_tables(db: &mut Database) -> BustubxResult<()> { } let schema = Arc::new(Schema::new(columns)); + // load last page id + let last_page_id = + load_table_last_page_id(&mut db.catalog, *first_page_id, schema.clone())?; let table_heap = TableHeap { schema: schema.clone(), buffer_pool: db.buffer_pool.clone(), first_page_id: AtomicPageId::new(*first_page_id), - last_page_id: AtomicPageId::new(*last_page_id), + last_page_id: AtomicPageId::new(last_page_id), }; db.catalog.load_table( TableReference::full(catalog, table_schema, table_name),