Struct IndexInfo

Source
pub struct IndexInfo { /* private fields */ }
Expand description

Wraps the raw sqlite3_index_info C struct, which represents the possible constraints and outputs the xBestIndex method should use and return. https://www.sqlite.org/c3ref/index_info.html

Implementations§

Source§

impl IndexInfo

Source

pub fn idx_flag(&self) -> i32

“Mask of SQLITE_INDEX_SCAN_* flags”

Source

pub fn constraints(&self) -> Vec<Constraint>

Examples found in repository?
examples/characters.rs (line 51)
49    fn best_index(&self, mut info: IndexInfo) -> core::result::Result<(), BestIndexError> {
50        let mut has_input = false;
51        for mut constraint in info.constraints() {
52            match column(constraint.column_idx()) {
53                Some(Columns::Input) => {
54                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
55                        constraint.set_omit(true);
56                        constraint.set_argv_index(1);
57                        has_input = true;
58                    } else {
59                        return Err(BestIndexError::Constraint);
60                    }
61                }
62                _ => todo!(),
63            }
64        }
65        if !has_input {
66            return Err(BestIndexError::Error);
67        }
68        info.set_estimated_cost(100000.0);
69        info.set_estimated_rows(100000);
70        info.set_idxnum(1);
71
72        Ok(())
73    }
More examples
Hide additional examples
examples/series.rs (line 57)
54    fn best_index(&self, mut info: IndexInfo) -> core::result::Result<(), BestIndexError> {
55        let mut has_start = false;
56        let mut has_stop = false;
57        for mut constraint in info.constraints() {
58            match column(constraint.column_idx()) {
59                Some(Columns::Start) => {
60                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
61                        constraint.set_omit(true);
62                        constraint.set_argv_index(1);
63                        has_start = true;
64                    } else {
65                        return Err(BestIndexError::Constraint);
66                    }
67                }
68                Some(Columns::Stop) => {
69                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
70                        constraint.set_omit(true);
71                        constraint.set_argv_index(2);
72                        has_stop = true;
73                    } else {
74                        return Err(BestIndexError::Constraint);
75                    }
76                }
77                _ => todo!(),
78            }
79        }
80        if !has_start || !has_stop {
81            return Err(BestIndexError::Error);
82        }
83        info.set_estimated_cost(100000.0);
84        info.set_estimated_rows(100000);
85        info.set_idxnum(1);
86
87        Ok(())
88    }
Source

pub fn order_bys(&self) -> Vec<OrderBy>

Source

pub fn set_idxnum(&mut self, value: i32)

Examples found in repository?
examples/characters.rs (line 70)
49    fn best_index(&self, mut info: IndexInfo) -> core::result::Result<(), BestIndexError> {
50        let mut has_input = false;
51        for mut constraint in info.constraints() {
52            match column(constraint.column_idx()) {
53                Some(Columns::Input) => {
54                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
55                        constraint.set_omit(true);
56                        constraint.set_argv_index(1);
57                        has_input = true;
58                    } else {
59                        return Err(BestIndexError::Constraint);
60                    }
61                }
62                _ => todo!(),
63            }
64        }
65        if !has_input {
66            return Err(BestIndexError::Error);
67        }
68        info.set_estimated_cost(100000.0);
69        info.set_estimated_rows(100000);
70        info.set_idxnum(1);
71
72        Ok(())
73    }
More examples
Hide additional examples
examples/series.rs (line 85)
54    fn best_index(&self, mut info: IndexInfo) -> core::result::Result<(), BestIndexError> {
55        let mut has_start = false;
56        let mut has_stop = false;
57        for mut constraint in info.constraints() {
58            match column(constraint.column_idx()) {
59                Some(Columns::Start) => {
60                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
61                        constraint.set_omit(true);
62                        constraint.set_argv_index(1);
63                        has_start = true;
64                    } else {
65                        return Err(BestIndexError::Constraint);
66                    }
67                }
68                Some(Columns::Stop) => {
69                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
70                        constraint.set_omit(true);
71                        constraint.set_argv_index(2);
72                        has_stop = true;
73                    } else {
74                        return Err(BestIndexError::Constraint);
75                    }
76                }
77                _ => todo!(),
78            }
79        }
80        if !has_start || !has_stop {
81            return Err(BestIndexError::Error);
82        }
83        info.set_estimated_cost(100000.0);
84        info.set_estimated_rows(100000);
85        info.set_idxnum(1);
86
87        Ok(())
88    }
Source

pub fn set_idxstr(&mut self, value: &str) -> Result<()>

Source

pub fn set_estimated_rows(&mut self, value: i64)

Examples found in repository?
examples/characters.rs (line 69)
49    fn best_index(&self, mut info: IndexInfo) -> core::result::Result<(), BestIndexError> {
50        let mut has_input = false;
51        for mut constraint in info.constraints() {
52            match column(constraint.column_idx()) {
53                Some(Columns::Input) => {
54                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
55                        constraint.set_omit(true);
56                        constraint.set_argv_index(1);
57                        has_input = true;
58                    } else {
59                        return Err(BestIndexError::Constraint);
60                    }
61                }
62                _ => todo!(),
63            }
64        }
65        if !has_input {
66            return Err(BestIndexError::Error);
67        }
68        info.set_estimated_cost(100000.0);
69        info.set_estimated_rows(100000);
70        info.set_idxnum(1);
71
72        Ok(())
73    }
More examples
Hide additional examples
examples/series.rs (line 84)
54    fn best_index(&self, mut info: IndexInfo) -> core::result::Result<(), BestIndexError> {
55        let mut has_start = false;
56        let mut has_stop = false;
57        for mut constraint in info.constraints() {
58            match column(constraint.column_idx()) {
59                Some(Columns::Start) => {
60                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
61                        constraint.set_omit(true);
62                        constraint.set_argv_index(1);
63                        has_start = true;
64                    } else {
65                        return Err(BestIndexError::Constraint);
66                    }
67                }
68                Some(Columns::Stop) => {
69                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
70                        constraint.set_omit(true);
71                        constraint.set_argv_index(2);
72                        has_stop = true;
73                    } else {
74                        return Err(BestIndexError::Constraint);
75                    }
76                }
77                _ => todo!(),
78            }
79        }
80        if !has_start || !has_stop {
81            return Err(BestIndexError::Error);
82        }
83        info.set_estimated_cost(100000.0);
84        info.set_estimated_rows(100000);
85        info.set_idxnum(1);
86
87        Ok(())
88    }
Source

pub fn set_estimated_cost(&mut self, value: f64)

“The estimatedCost field should be set to the estimated number of disk access operations required to execute this query against the virtual table.” https://www.sqlite.org/vtab.html#outputs

Examples found in repository?
examples/characters.rs (line 68)
49    fn best_index(&self, mut info: IndexInfo) -> core::result::Result<(), BestIndexError> {
50        let mut has_input = false;
51        for mut constraint in info.constraints() {
52            match column(constraint.column_idx()) {
53                Some(Columns::Input) => {
54                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
55                        constraint.set_omit(true);
56                        constraint.set_argv_index(1);
57                        has_input = true;
58                    } else {
59                        return Err(BestIndexError::Constraint);
60                    }
61                }
62                _ => todo!(),
63            }
64        }
65        if !has_input {
66            return Err(BestIndexError::Error);
67        }
68        info.set_estimated_cost(100000.0);
69        info.set_estimated_rows(100000);
70        info.set_idxnum(1);
71
72        Ok(())
73    }
More examples
Hide additional examples
examples/series.rs (line 83)
54    fn best_index(&self, mut info: IndexInfo) -> core::result::Result<(), BestIndexError> {
55        let mut has_start = false;
56        let mut has_stop = false;
57        for mut constraint in info.constraints() {
58            match column(constraint.column_idx()) {
59                Some(Columns::Start) => {
60                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
61                        constraint.set_omit(true);
62                        constraint.set_argv_index(1);
63                        has_start = true;
64                    } else {
65                        return Err(BestIndexError::Constraint);
66                    }
67                }
68                Some(Columns::Stop) => {
69                    if constraint.usable() && constraint.op() == Some(ConstraintOperator::EQ) {
70                        constraint.set_omit(true);
71                        constraint.set_argv_index(2);
72                        has_stop = true;
73                    } else {
74                        return Err(BestIndexError::Constraint);
75                    }
76                }
77                _ => todo!(),
78            }
79        }
80        if !has_start || !has_stop {
81            return Err(BestIndexError::Error);
82        }
83        info.set_estimated_cost(100000.0);
84        info.set_estimated_rows(100000);
85        info.set_idxnum(1);
86
87        Ok(())
88    }
Source

pub fn columns_used(&self) -> u64

Source

pub fn distinct(&self) -> i32

Trait Implementations§

Source§

impl Debug for IndexInfo

Source§

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

Formats the value using the given formatter. Read more

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