pub struct Index { /* private fields */ }Expand description
An index is a group of key values and pointers.
Implementations§
source§impl Index
impl Index
sourcepub const unsafe fn from_ids_unchecked(
space_id: SpaceId,
index_id: IndexId
) -> Self
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.
pub fn meta(&self) -> Result<Metadata<'_>, Error>
pub fn drop(&self) -> Result<(), Error>
sourcepub fn get<K>(&self, key: &K) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer + ?Sized,
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
sourcepub fn select<K>(
&self,
iterator_type: IteratorType,
key: &K
) -> Result<IndexIterator, Error>where
K: ToTupleBuffer + ?Sized,
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 typekey- encoded key in MsgPack Array format ([part1, part2, ...]).
sourcepub fn delete<K>(&self, key: &K) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer + ?Sized,
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
sourcepub fn update<K, Op>(
&self,
key: &K,
ops: impl AsRef<[Op]>
) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer + ?Sized,
Op: ToTupleBuffer,
pub fn update<K, Op>( &self, key: &K, ops: impl AsRef<[Op]> ) -> Result<Option<Tuple>, Error>where K: ToTupleBuffer + ?Sized, Op: ToTupleBuffer,
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()
sourcepub unsafe fn update_mp<K>(
&self,
key: &K,
ops: &[Vec<u8>]
) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer + ?Sized,
👎Deprecated: use update_raw instead
pub unsafe fn update_mp<K>( &self, key: &K, ops: &[Vec<u8>] ) -> Result<Option<Tuple>, Error>where K: ToTupleBuffer + ?Sized,
Safety
ops must be a slice of valid msgpack arrays.
sourcepub unsafe fn update_raw(
&self,
key: &[u8],
ops: &[u8]
) -> Result<Option<Tuple>, Error>
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.
sourcepub fn upsert<T, Op>(
&self,
value: &T,
ops: impl AsRef<[Op]>
) -> Result<(), Error>where
T: ToTupleBuffer + ?Sized,
Op: ToTupleBuffer,
pub fn upsert<T, Op>( &self, value: &T, ops: impl AsRef<[Op]> ) -> Result<(), Error>where T: ToTupleBuffer + ?Sized, Op: ToTupleBuffer,
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()
sourcepub unsafe fn upsert_mp<T>(
&self,
value: &T,
ops: &[Vec<u8>]
) -> Result<(), Error>where
T: ToTupleBuffer + ?Sized,
👎Deprecated: use upsert_raw instead
pub unsafe fn upsert_mp<T>( &self, value: &T, ops: &[Vec<u8>] ) -> Result<(), Error>where T: ToTupleBuffer + ?Sized,
Safety
ops must be a slice of valid msgpack arrays.
sourcepub unsafe fn upsert_raw(&self, value: &[u8], ops: &[u8]) -> Result<(), Error>
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.
pub fn is_empty(&self) -> Result<bool, Error>
sourcepub fn bsize(&self) -> Result<usize, Error>
pub fn bsize(&self) -> Result<usize, Error>
Return the number of bytes used in memory by the index.
sourcepub fn random(&self, seed: u32) -> Result<Option<Tuple>, Error>
pub fn random(&self, seed: u32) -> Result<Option<Tuple>, Error>
Return a random tuple from the index (useful for statistical analysis).
rnd- random seed
sourcepub fn min<K>(&self, key: &K) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer + ?Sized,
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
sourcepub fn max<K>(&self, key: &K) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer + ?Sized,
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
sourcepub fn count<K>(
&self,
iterator_type: IteratorType,
key: &K
) -> Result<usize, Error>where
K: ToTupleBuffer + ?Sized,
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 typekey- encoded key in MsgPack Array format ([part1, part2, ...]).
sourcepub fn extract_key(&self, tuple: Tuple) -> Tuple
pub fn extract_key(&self, tuple: Tuple) -> Tuple
Extract key from tuple according to key definition of given
index. Returned buffer is allocated on box_txn_alloc() with
this key.
tuple- tuple from which need to extract key.