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: StringCatalog 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: IndexEntriesImplementations§
Source§impl SecondaryIndex
impl SecondaryIndex
Sourcepub fn new(
name: String,
table_name: String,
column_name: String,
datatype: &DataType,
is_unique: bool,
origin: IndexOrigin,
) -> Result<Self>
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).
Sourcepub fn synthesized_sql(&self) -> String
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.
Sourcepub fn auto_name(table_name: &str, column_name: &str) -> String
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.
Sourcepub fn would_violate_unique(&self, value: &Value) -> bool
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.
Sourcepub fn insert(&mut self, value: &Value, rowid: i64) -> Result<()>
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.
Sourcepub fn remove(&mut self, value: &Value, rowid: i64)
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).
Sourcepub fn lookup(&self, value: &Value) -> Vec<i64>
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.
Sourcepub fn iter_entries(&self) -> Box<dyn Iterator<Item = (Value, i64)> + '_>
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
impl Clone for SecondaryIndex
Source§fn clone(&self) -> SecondaryIndex
fn clone(&self) -> SecondaryIndex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more