Skip to content

Commit 9ba0b95

Browse files
committed
Restore use of ColId
1 parent 30e1a93 commit 9ba0b95

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

crates/core/src/db/datastore/locking_tx_datastore/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl CommittedState {
152152

153153
// Add all newly created indexes to the committed state
154154
for (_, index) in table.indexes {
155-
if !commit_table.indexes.contains_key(&index.cols) {
155+
if !commit_table.indexes.contains_key(&index.cols.clone().map(ColId)) {
156156
commit_table.insert_index(index);
157157
}
158158
}
@@ -190,7 +190,7 @@ impl CommittedState {
190190
value: &'a AlgebraicValue,
191191
) -> Option<BTreeIndexRangeIter<'a>> {
192192
if let Some(table) = self.tables.get(table_id) {
193-
table.index_seek(cols, value)
193+
table.index_seek(cols.map(ColId), value)
194194
} else {
195195
None
196196
}
@@ -302,7 +302,7 @@ impl TxState {
302302
cols: NonEmpty<u32>,
303303
value: &'a AlgebraicValue,
304304
) -> Option<BTreeIndexRangeIter<'a>> {
305-
self.insert_tables.get(table_id)?.index_seek(cols, value)
305+
self.insert_tables.get(table_id)?.index_seek(cols.map(ColId), value)
306306
}
307307
}
308308

@@ -457,7 +457,7 @@ impl Inner {
457457
index_row.is_unique,
458458
);
459459
index.build_from_rows(table.scan_rows())?;
460-
table.indexes.insert(index_row.cols, index);
460+
table.indexes.insert(index_row.cols.map(ColId), index);
461461
}
462462
Ok(())
463463
}
@@ -972,7 +972,7 @@ impl Inner {
972972
index_id: index_id.0,
973973
});
974974

975-
insert_table.indexes.insert(index.cols.clone(), insert_index);
975+
insert_table.indexes.insert(index.cols.clone().map(ColId), insert_index);
976976
Ok(())
977977
}
978978

@@ -1008,7 +1008,7 @@ impl Inner {
10081008
}
10091009
}
10101010
for col in cols {
1011-
table.indexes.remove(&col);
1011+
table.indexes.remove(&col.clone().map(ColId));
10121012
table.schema.indexes.retain(|x| x.cols != col);
10131013
}
10141014
}
@@ -1025,7 +1025,7 @@ impl Inner {
10251025
}
10261026
}
10271027
for col in cols {
1028-
insert_table.indexes.remove(&col);
1028+
insert_table.indexes.remove(&col.clone().map(ColId));
10291029
insert_table.schema.indexes.retain(|x| x.cols != col);
10301030
}
10311031
}

crates/core/src/db/datastore/locking_tx_datastore/table.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{
22
btree_index::{BTreeIndex, BTreeIndexIter, BTreeIndexRangeIter},
33
RowId,
44
};
5-
use crate::db::datastore::traits::TableSchema;
5+
use crate::db::datastore::traits::{ColId, TableSchema};
66
use nonempty::NonEmpty;
77
use spacetimedb_sats::{AlgebraicValue, ProductType, ProductValue};
88
use std::{
@@ -13,14 +13,14 @@ use std::{
1313
pub(crate) struct Table {
1414
pub(crate) row_type: ProductType,
1515
pub(crate) schema: TableSchema,
16-
pub(crate) indexes: HashMap<NonEmpty<u32>, BTreeIndex>,
16+
pub(crate) indexes: HashMap<NonEmpty<ColId>, BTreeIndex>,
1717
pub(crate) rows: BTreeMap<RowId, ProductValue>,
1818
}
1919

2020
impl Table {
2121
pub(crate) fn insert_index(&mut self, mut index: BTreeIndex) {
2222
index.build_from_rows(self.scan_rows()).unwrap();
23-
self.indexes.insert(index.cols.clone(), index);
23+
self.indexes.insert(index.cols.clone().map(ColId), index);
2424
}
2525

2626
pub(crate) fn insert(&mut self, row_id: RowId, row: ProductValue) {
@@ -33,7 +33,7 @@ impl Table {
3333
pub(crate) fn delete(&mut self, row_id: &RowId) -> Option<ProductValue> {
3434
let row = self.rows.remove(row_id)?;
3535
for (cols, index) in self.indexes.iter_mut() {
36-
let col_value = row.project_not_empty(cols).unwrap();
36+
let col_value = row.project_not_empty(&cols.clone().map(|x| x.0)).unwrap();
3737
index.delete(&col_value, row_id)
3838
}
3939
Some(row)
@@ -64,19 +64,19 @@ impl Table {
6464
/// For a unique index this will always yield at most one `RowId`.
6565
pub(crate) fn index_seek<'a>(
6666
&'a self,
67-
cols: NonEmpty<u32>,
67+
cols: NonEmpty<ColId>,
6868
value: &'a AlgebraicValue,
6969
) -> Option<BTreeIndexRangeIter<'a>> {
7070
self.indexes.get(&cols).map(|index| index.seek(value))
7171
}
7272

73-
pub(crate) fn _index_scan(&self, cols: NonEmpty<u32>) -> BTreeIndexIter<'_> {
73+
pub(crate) fn _index_scan(&self, cols: NonEmpty<ColId>) -> BTreeIndexIter<'_> {
7474
self.indexes.get(&cols).unwrap().scan()
7575
}
7676

7777
pub(crate) fn _index_range_scan(
7878
&self,
79-
cols: NonEmpty<u32>,
79+
cols: NonEmpty<ColId>,
8080
range: impl RangeBounds<AlgebraicValue>,
8181
) -> BTreeIndexRangeIter<'_> {
8282
self.indexes.get(&cols).unwrap().scan_range(range)

0 commit comments

Comments
 (0)