From e109385c1e06d6c782428a2ca00a790894da33b5 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Mon, 20 May 2024 17:52:57 +0200 Subject: [PATCH] remove BTreeIndex::name again (#1251) --- .../locking_tx_datastore/committed_state.rs | 1 - .../datastore/locking_tx_datastore/mut_tx.rs | 8 +---- crates/table/benches/page_manager.rs | 2 +- crates/table/src/btree_index.rs | 8 ++--- crates/table/src/table.rs | 32 +++++++++++-------- 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/crates/core/src/db/datastore/locking_tx_datastore/committed_state.rs b/crates/core/src/db/datastore/locking_tx_datastore/committed_state.rs index 13e5cf4cd3..5dcd0af1da 100644 --- a/crates/core/src/db/datastore/locking_tx_datastore/committed_state.rs +++ b/crates/core/src/db/datastore/locking_tx_datastore/committed_state.rs @@ -307,7 +307,6 @@ impl CommittedState { table.row_layout(), &index_row.columns, index_row.is_unique, - index_row.index_name, )?; index.build_from_rows(&index_row.columns, table.scan_rows(blob_store))?; table.indexes.insert(index_row.columns, index); diff --git a/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs b/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs index fa2b41215f..3b07c81c20 100644 --- a/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs +++ b/crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs @@ -324,13 +324,7 @@ impl MutTxId { self.tx_state.get_table_and_blob_store(table_id).unwrap() }; - let mut insert_index = BTreeIndex::new( - index.index_id, - table.row_layout(), - &index.columns, - index.is_unique, - index.index_name.clone(), - )?; + let mut insert_index = BTreeIndex::new(index.index_id, table.row_layout(), &index.columns, index.is_unique)?; insert_index.build_from_rows(&index.columns, table.scan_rows(blob_store))?; // NOTE: Also add all the rows in the already committed table to the index. diff --git a/crates/table/benches/page_manager.rs b/crates/table/benches/page_manager.rs index fb1873ca41..82dbb71269 100644 --- a/crates/table/benches/page_manager.rs +++ b/crates/table/benches/page_manager.rs @@ -693,7 +693,7 @@ fn make_table_with_indexes() -> Table { let mut tbl = Table::new(schema.into(), SquashedOffset::COMMITTED_STATE); let cols = R::indexed_columns(); - let idx = BTreeIndex::new(IndexId(0), &R::row_type().into(), &cols, false, "idx").unwrap(); + let idx = BTreeIndex::new(IndexId(0), &R::row_type().into(), &cols, false).unwrap(); tbl.insert_index(&NullBlobStore, cols, idx); tbl diff --git a/crates/table/src/btree_index.rs b/crates/table/src/btree_index.rs index 8f498af7d7..71a7a55cc6 100644 --- a/crates/table/src/btree_index.rs +++ b/crates/table/src/btree_index.rs @@ -325,11 +325,9 @@ pub struct BTreeIndex { pub(crate) is_unique: bool, /// The actual index, specialized for the appropriate key type. idx: TypedIndex, - /// The index name, used for reporting unique constraint violations. - pub(crate) name: Box, } -static_assert_size!(BTreeIndex, 56); +static_assert_size!(BTreeIndex, 40); impl BTreeIndex { /// Returns a new possibly unique index, with `index_id` for a set of columns. @@ -338,7 +336,6 @@ impl BTreeIndex { row_type: &RowTypeLayout, indexed_columns: &ColList, is_unique: bool, - name: impl Into>, ) -> Result { // If the index is on a single column of a primitive type, // use a homogeneous map with a native key type. @@ -372,7 +369,6 @@ impl BTreeIndex { index_id, is_unique, idx: typed_index, - name: name.into(), }) } @@ -471,7 +467,7 @@ mod test { fn new_index(row_type: &ProductType, cols: &ColList, is_unique: bool) -> BTreeIndex { let row_layout: RowTypeLayout = row_type.clone().into(); - BTreeIndex::new(0.into(), &row_layout, cols, is_unique, "test_index").unwrap() + BTreeIndex::new(0.into(), &row_layout, cols, is_unique).unwrap() } fn table(ty: ProductType) -> Table { diff --git a/crates/table/src/table.rs b/crates/table/src/table.rs index 17b1202c82..45e17f1f10 100644 --- a/crates/table/src/table.rs +++ b/crates/table/src/table.rs @@ -573,14 +573,7 @@ impl Table { new.insert_index( &NullBlobStore, cols.clone(), - BTreeIndex::new( - index.index_id, - &self.inner.row_layout, - cols, - index.is_unique, - index.name.clone(), - ) - .unwrap(), + BTreeIndex::new(index.index_id, &self.inner.row_layout, cols, index.is_unique).unwrap(), ); } new @@ -912,7 +905,7 @@ impl IndexScanIter<'_> { #[derive(Error, Debug, PartialEq, Eq)] #[error("Unique constraint violation '{}' in table '{}': column(s): '{:?}' value: {}", constraint_name, table_name, cols, value.to_satn())] pub struct UniqueConstraintViolation { - pub constraint_name: String, + pub constraint_name: Box, pub table_name: Box, pub cols: Vec>, pub value: AlgebraicValue, @@ -930,14 +923,27 @@ impl Table { ) -> UniqueConstraintViolation { let schema = self.get_schema(); + // Fetch the table name. + let table_name = schema.table_name.clone(); + + // Fetch the names of the columns used in the index. let cols = cols .iter() .map(|x| schema.columns()[x.idx()].col_name.clone()) .collect(); + // Fetch the name of the index. + let constraint_name = schema + .indexes + .iter() + .find(|i| i.index_id == index.index_id) + .unwrap() + .index_name + .clone(); + UniqueConstraintViolation { - constraint_name: index.name.clone().into(), - table_name: schema.table_name.clone(), + constraint_name, + table_name, cols, value, } @@ -1049,7 +1055,7 @@ pub(crate) mod test { let mut table = Table::new(schema.into(), SquashedOffset::COMMITTED_STATE); let cols = ColList::new(0.into()); - let index = BTreeIndex::new(index_schema.index_id, &table.inner.row_layout, &cols, true, index_name).unwrap(); + let index = BTreeIndex::new(index_schema.index_id, &table.inner.row_layout, &cols, true).unwrap(); table.insert_index(&NullBlobStore, cols, index); // Insert the row (0, 0). @@ -1066,7 +1072,7 @@ pub(crate) mod test { cols, value, })) => { - assert_eq!(constraint_name, index_name); + assert_eq!(&*constraint_name, index_name); assert_eq!(&*table_name, "UniqueIndexed"); assert_eq!(cols.iter().map(|c| c.to_string()).collect::>(), &["unique_col"]); assert_eq!(value, AlgebraicValue::I32(0));