TableIndex

Struct TableIndex 

Source
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: AlgebraicType

The key type of this index. This is the projection of the row type to the types of the columns indexed.

§indexed_columns: ColList

Given 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

Source

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.

Source

pub fn clone_structure(&self) -> Self

Clones the structure of this index but not the indexed elements, so the returned index is empty.

Source

pub fn is_unique(&self) -> bool

Returns whether this is a unique index or not.

Source

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.

Source

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.

Source

pub fn contains_any(&self, value: &AlgebraicValue) -> bool

Returns whether value is in this index.

Source

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.

Source

pub fn seek_point(&self, key: &AlgebraicValue) -> TableIndexPointIter<'_>

Returns an iterator that yields all the RowPointers for the given key.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn num_keys(&self) -> usize

The number of unique keys in this index.

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl MemoryUsage for TableIndex

Source§

fn heap_usage(&self) -> usize

The heap memory usage of this type. The default implementation returns 0.
Source§

impl PartialEq for TableIndex

Source§

fn eq(&self, other: &TableIndex) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TableIndex

Source§

impl StructuralPartialEq for TableIndex

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.