Struct tarantool::index::Index

source ·
pub struct Index { /* private fields */ }
Expand description

An index is a group of key values and pointers.

Implementations§

source§

impl Index

source

pub const unsafe fn from_ids_unchecked( space_id: SpaceId, index_id: IndexId ) -> Self

Create an Index with corresponding space and index ids.

§Safety

ids must be valid tarantool space/index id. Only use this function with ids acquired from tarantool in some way, e.g. from lua code.

source

pub fn id(&self) -> u32

Return id of this index.

source

pub fn space_id(&self) -> u32

Return the space id of this index.

source

pub fn meta(&self) -> Result<Metadata<'_>, Error>

source

pub fn drop(&self) -> Result<(), Error>

source

pub fn get<K>(&self, key: &K) -> Result<Option<Tuple>, Error>
where K: ToTupleBuffer + ?Sized,

Get a tuple from index by the key.

Please note that this function works much faster than select

  • key - encoded key in MsgPack Array format ([part1, part2, ...]).

Returns a tuple or None if index is empty

source

pub fn select<K>( &self, iterator_type: IteratorType, key: &K ) -> Result<IndexIterator, Error>
where K: ToTupleBuffer + ?Sized,

Allocate and initialize iterator for index.

This is an alternative to space.select() which goes via a particular index and can make use of additional parameter that specify the iterator type.

  • type - iterator type
  • key - encoded key in MsgPack Array format ([part1, part2, ...]).
source

pub fn delete<K>(&self, key: &K) -> Result<Option<Tuple>, Error>
where K: ToTupleBuffer + ?Sized,

Delete a tuple identified by a key.

Same as space.delete(), but a key is searched in this index instead of in the primary-key index. This index ought to be unique.

  • key - encoded key in MsgPack Array format ([part1, part2, ...]).

Returns the deleted tuple

source

pub fn update<K, Op>( &self, key: &K, ops: impl AsRef<[Op]> ) -> Result<Option<Tuple>, Error>

Update a tuple.

Same as space.update(), but a key is searched in this index instead of primary key. This index ought to be unique.

  • key - encoded key in MsgPack Array format ([part1, part2, ...]).
  • ops - encoded operations in MsgPack array format, e.g. [['=', field_id, value], ['!', 2, 'xxx']]

Returns a new tuple.

See also: index.upsert()

source

pub unsafe fn update_mp<K>( &self, key: &K, ops: &[Vec<u8>] ) -> Result<Option<Tuple>, Error>
where K: ToTupleBuffer + ?Sized,

👎Deprecated: use update_raw instead
§Safety

ops must be a slice of valid msgpack arrays.

source

pub unsafe fn update_raw( &self, key: &[u8], ops: &[u8] ) -> Result<Option<Tuple>, Error>

§Safety

key must be a valid msgpack array. ops must be a valid msgpack array of msgpack arrays.

source

pub fn upsert<T, Op>( &self, value: &T, ops: impl AsRef<[Op]> ) -> Result<(), Error>

Execute an UPSERT request.

Will try to insert tuple. Update if already exists.

  • value - encoded tuple in MsgPack Array format ([field1, field2, ...])
  • ops - encoded operations in MsgPack array format, e.g. [['=', field_id, value], ['!', 2, 'xxx']]

See also: index.update()

source

pub unsafe fn upsert_mp<T>( &self, value: &T, ops: &[Vec<u8>] ) -> Result<(), Error>
where T: ToTupleBuffer + ?Sized,

👎Deprecated: use upsert_raw instead
§Safety

ops must be a slice of valid msgpack arrays.

source

pub unsafe fn upsert_raw(&self, value: &[u8], ops: &[u8]) -> Result<(), Error>

§Safety

value must be a valid msgpack array. ops must be a valid msgpack array of msgpack arrays.

source

pub fn len(&self) -> Result<usize, Error>

Return the number of elements in the index.

source

pub fn is_empty(&self) -> Result<bool, Error>

source

pub fn bsize(&self) -> Result<usize, Error>

Return the number of bytes used in memory by the index.

source

pub fn random(&self, seed: u32) -> Result<Option<Tuple>, Error>

Return a random tuple from the index (useful for statistical analysis).

  • rnd - random seed
source

pub fn min<K>(&self, key: &K) -> Result<Option<Tuple>, Error>
where K: ToTupleBuffer + ?Sized,

Return a first (minimal) tuple that matched the provided key.

  • key - encoded key in MsgPack Array format ([part1, part2, ...]).

Returns a tuple or None if index is empty

source

pub fn max<K>(&self, key: &K) -> Result<Option<Tuple>, Error>
where K: ToTupleBuffer + ?Sized,

Return a last (maximal) tuple that matched the provided key.

  • key - encoded key in MsgPack Array format ([part1, part2, ...]).

Returns a tuple or None if index is empty

source

pub fn count<K>( &self, iterator_type: IteratorType, key: &K ) -> Result<usize, Error>
where K: ToTupleBuffer + ?Sized,

Count the number of tuples that matched the provided key.

  • type - iterator type
  • key - encoded key in MsgPack Array format ([part1, part2, ...]).
source

pub unsafe fn extract_key(&self, tuple: Tuple) -> Tuple

Extract key from tuple according to key definition of given index.

§Safety

The current index & it’s space must exist and tuple must conform to the space format.

You should probably use KeyDef::extract_key instead.

Trait Implementations§

source§

impl Clone for Index

source§

fn clone(&self) -> Index

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Index

source§

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

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

impl PartialEq for Index

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Index

source§

impl StructuralPartialEq for Index

Auto Trait Implementations§

§

impl Freeze for Index

§

impl RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnwindSafe for Index

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<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> IntoClones<(T,)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.