pub struct TableIndex {
pub key_type: AlgebraicType,
pub indexed_columns: ColList,
/* private fields */
}Expand description
An index on a set of [ColId]s of a table.
Fields§
§key_type: AlgebraicTypeThe key type of this index. This is the projection of the row type to the types of the columns indexed.
indexed_columns: ColListGiven a full row, typed at some ty: ProductType,
these columns are the ones that this index indexes.
Projecting the ty to self.indexed_columns yields the index’s type self.key_type.
Implementations§
Source§impl TableIndex
impl TableIndex
Sourcepub fn new(
row_type: &ProductType,
index_algo: &IndexAlgorithm,
is_unique: bool,
) -> Result<Self, InvalidFieldError>
pub fn new( row_type: &ProductType, index_algo: &IndexAlgorithm, is_unique: bool, ) -> Result<Self, InvalidFieldError>
Returns a new possibly unique index, with index_id for a choice of indexing algorithm.
Sourcepub fn clone_structure(&self) -> Self
pub fn clone_structure(&self) -> Self
Clones the structure of this index but not the indexed elements, so the returned index is empty.
Sourcepub unsafe fn check_and_insert(
&mut self,
row_ref: RowRef<'_>,
) -> Result<(), RowPointer>
pub unsafe fn check_and_insert( &mut self, row_ref: RowRef<'_>, ) -> Result<(), RowPointer>
Inserts ptr with the value row to this index.
This index will extract the necessary values from row based on self.indexed_columns.
Returns Err(existing_row) if this insertion would violate a unique constraint.
§Safety
Caller promises that projecting the row_ref’s type
to the index’s columns equals the index’s key type.
This is entailed by an index belonging to the table’s schema.
It also follows from row_ref’s type/layout
being the same as passed in on self’s construction.
Sourcepub fn delete(&mut self, row_ref: RowRef<'_>) -> Result<bool, InvalidFieldError>
pub fn delete(&mut self, row_ref: RowRef<'_>) -> Result<bool, InvalidFieldError>
Deletes row_ref with its indexed value row_ref.project(&self.indexed_columns) from this index.
Returns whether ptr was present.
Sourcepub fn contains_any(&self, value: &AlgebraicValue) -> bool
pub fn contains_any(&self, value: &AlgebraicValue) -> bool
Returns whether value is in this index.
Sourcepub fn count(&self, value: &AlgebraicValue) -> Option<usize>
pub fn count(&self, value: &AlgebraicValue) -> Option<usize>
Returns the number of rows associated with this value.
Returns None if 0.
Returns Some(1) if the index is unique.
Sourcepub fn seek_point(&self, key: &AlgebraicValue) -> TableIndexPointIter<'_> ⓘ
pub fn seek_point(&self, key: &AlgebraicValue) -> TableIndexPointIter<'_> ⓘ
Returns an iterator that yields all the RowPointers for the given key.
Sourcepub fn seek_range(
&self,
range: &impl RangeBounds<AlgebraicValue>,
) -> TableIndexRangeIter<'_> ⓘ
pub fn seek_range( &self, range: &impl RangeBounds<AlgebraicValue>, ) -> TableIndexRangeIter<'_> ⓘ
Returns an iterator over the TableIndex that yields all the RowPointers
that fall within the specified range.
Sourcepub unsafe fn build_from_rows<'table>(
&mut self,
rows: impl IntoIterator<Item = RowRef<'table>>,
) -> Result<(), RowPointer>
pub unsafe fn build_from_rows<'table>( &mut self, rows: impl IntoIterator<Item = RowRef<'table>>, ) -> Result<(), RowPointer>
Extends TableIndex with rows.
Returns the first unique constraint violation caused when adding this index, if any.
§Safety
Caller promises that projecting any of the row_ref’s type
to the index’s columns equals the index’s key type.
This is entailed by an index belonging to the table’s schema.
It also follows from row_ref’s type/layout
being the same as passed in on self’s construction.
Sourcepub fn can_merge(
&self,
other: &Self,
ignore: impl Fn(&RowPointer) -> bool,
) -> Result<(), RowPointer>
pub fn can_merge( &self, other: &Self, ignore: impl Fn(&RowPointer) -> bool, ) -> Result<(), RowPointer>
Returns an error with the first unique constraint violation that
would occur if self and other were to be merged.
The closure ignore indicates whether a row in self should be ignored.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Deletes all entries from the index, leaving it empty.
When inserting a newly-created index into the committed state,
we clear the tx state’s index and insert it,
rather than constructing a new TableIndex.
Sourcepub fn num_rows(&self) -> u64
pub fn num_rows(&self) -> u64
The number of rows stored in this index.
Note that, for non-unique indexes, this may be larger than Self::num_keys.
This method runs in constant time.
Sourcepub fn num_key_bytes(&self) -> u64
pub fn num_key_bytes(&self) -> u64
The number of bytes stored in keys in this index.
For non-unique indexes, duplicate keys are counted once for each row that refers to them, even though the internal storage may deduplicate them as an optimization.
This method runs in constant time.
See the KeySize trait for more details on how this method computes its result.
Trait Implementations§
Source§impl Debug for TableIndex
impl Debug for TableIndex
Source§impl MemoryUsage for TableIndex
impl MemoryUsage for TableIndex
Source§fn heap_usage(&self) -> usize
fn heap_usage(&self) -> usize
Source§impl PartialEq for TableIndex
impl PartialEq for TableIndex
impl Eq for TableIndex
impl StructuralPartialEq for TableIndex
Auto Trait Implementations§
impl Freeze for TableIndex
impl RefUnwindSafe for TableIndex
impl Send for TableIndex
impl Sync for TableIndex
impl Unpin for TableIndex
impl UnwindSafe for TableIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more