Skip to main content

SecondaryIndex

Struct SecondaryIndex 

Source
pub struct SecondaryIndex {
    pub name: String,
    pub table_name: String,
    pub column_name: String,
    pub is_unique: bool,
    pub origin: IndexOrigin,
    pub entries: IndexEntries,
}
Expand description

One secondary index on a single column. Multi-column composite indexes are on the longer-term list; the column_name field stays singular for now.

Fields§

§name: String

Catalog name. For auto indexes: sqlrite_autoindex_<table>_<col>. For explicit indexes: the user-supplied identifier from CREATE INDEX.

§table_name: String§column_name: String§is_unique: bool§origin: IndexOrigin§entries: IndexEntries

Implementations§

Source§

impl SecondaryIndex

Source

pub fn new( name: String, table_name: String, column_name: String, datatype: &DataType, is_unique: bool, origin: IndexOrigin, ) -> Result<Self>

Builds an empty index over a column of the given datatype. Returns an error for unsupported datatypes (Real, Bool, None, Invalid).

Source

pub fn synthesized_sql(&self) -> String

Synthesizes a CREATE INDEX statement for sqlrite_master.sql. For auto indexes this is a synthetic form; for explicit indexes the caller can override with the original user text if it has been preserved. Used by the persistence path in Phase 3e.4.

Source

pub fn auto_name(table_name: &str, column_name: &str) -> String

Standard name for the auto-generated index of a UNIQUE/PK column. Uniform across save/open so indexes persist under a stable name.

Source

pub fn would_violate_unique(&self, value: &Value) -> bool

Returns true iff inserting value would violate the UNIQUE constraint — i.e., the index already has an entry for this value and self.is_unique is set. Null values are never indexed and never conflict.

Source

pub fn insert(&mut self, value: &Value, rowid: i64) -> Result<()>

Adds a (value, rowid) entry. Null values are ignored (NULL in an indexed column stays out of the index). Type mismatches — e.g. calling this with a Text value against an Integer index — return an error rather than silently skipping.

Source

pub fn remove(&mut self, value: &Value, rowid: i64)

Removes a (value, rowid) entry. If the value has other rowids attached they remain; if this was the last rowid, the value key is pruned. A no-op if the entry isn’t present (simpler than failing — UPDATE paths rely on this).

Source

pub fn lookup(&self, value: &Value) -> Vec<i64>

Returns every rowid currently associated with value. For a unique index this is at most one; for a non-unique index it can be many. Empty Vec if the value isn’t present.

Source

pub fn iter_entries(&self) -> Box<dyn Iterator<Item = (Value, i64)> + '_>

Iterates every (value, rowid) pair in ascending-value order. The rowids for a given value come out in insertion order, which happens to match ascending rowid order in practice because rows are inserted in rowid-ascending sequence during a bulk load. Phase 3e.4 uses this to serialize the index to its B-Tree.

Trait Implementations§

Source§

impl Clone for SecondaryIndex

Source§

fn clone(&self) -> SecondaryIndex

Returns a duplicate 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 SecondaryIndex

Source§

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

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

impl PartialEq for SecondaryIndex

Source§

fn eq(&self, other: &Self) -> 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.

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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

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.