Struct spacetimedb_vm::expr::QueryExpr

source ·
pub struct QueryExpr {
    pub source: SourceExpr,
    pub query: Vec<Query>,
}

Fields§

§source: SourceExpr§query: Vec<Query>

Implementations§

source§

impl QueryExpr

source

pub fn new<T: Into<SourceExpr>>(source: T) -> Self

source

pub fn walk_sources<E>( &self, on_source: &mut impl FnMut(&SourceExpr) -> Result<(), E> ) -> Result<(), E>

Iterate over all SourceExprs involved in the QueryExpr.

Sources are yielded from left to right. Duplicates are not filtered out.

source

pub fn reads_from_table(&self, id: &TableId) -> bool

Does this query read from a given table?

source

pub fn with_index_eq( self, table: DbTable, columns: ColList, value: AlgebraicValue ) -> Self

source

pub fn with_index_lower_bound( self, table: DbTable, columns: ColList, value: AlgebraicValue, inclusive: bool ) -> Self

source

pub fn with_index_upper_bound( self, table: DbTable, columns: ColList, value: AlgebraicValue, inclusive: bool ) -> Self

source

pub fn with_select<O>(self, op: O) -> Self
where O: Into<ColumnOp>,

source

pub fn with_select_cmp<LHS, RHS, O>(self, op: O, lhs: LHS, rhs: RHS) -> Self
where LHS: Into<FieldExpr>, RHS: Into<FieldExpr>, O: Into<OpQuery>,

source

pub fn with_project( self, cols: &[FieldExpr], wildcard_table_id: Option<TableId> ) -> Self

source

pub fn with_join_inner( self, with: impl Into<QueryExpr>, lhs: FieldName, rhs: FieldName, semi: bool ) -> Self

source

pub fn try_semi_join(self) -> QueryExpr

Try to turn an inner join followed by a projection into a semijoin.

This optimization recognizes queries of the form:

QueryExpr {
  source: LHS,
  query: [
    JoinInner(JoinExpr {
      rhs: RHS,
      semi: false,
      ..
    }),
    Project(LHS.*),
    ...
  ]
}

And combines the JoinInner with the Project into a JoinInner with semi: true.

Current limitations of this optimization:

  • The JoinInner must be the first (0th) element of the query. Future work could search through the query to find any applicable JoinInners, but the current implementation inspects only the first expr. This is likely sufficient because this optimization is primarily useful for enabling try_index_join, which is fundamentally limited to operate on the first expr. Note that we still get to optimize incremental joins, because we first optimize the original query with DbTable sources, which results in an IndexJoin then we replace the sources with MemTables and go back to a [JoinInner] with semi: true.
  • The Project must immediately follow the JoinInner, with no intervening exprs. Future work could search through intervening exprs to detect that the RHS table is unused.
  • The LHS/source table must be a DbTable, not a MemTable. This is so we can recognize a wildcard project by its table id. Future work could inspect the set of projected fields and compare them to the LHS table’s header instead.
source

pub fn optimize(self, row_count: &impl Fn(TableId, &str) -> i64) -> Self

Trait Implementations§

source§

impl AuthAccess for QueryExpr

source§

fn check_auth(&self, owner: Identity, caller: Identity) -> Result<(), AuthError>

source§

impl Clone for QueryExpr

source§

fn clone(&self) -> QueryExpr

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 QueryExpr

source§

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

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

impl From<IndexJoin> for QueryExpr

source§

fn from(join: IndexJoin) -> Self

Converts to this type from the input type.
source§

impl From<QueryExpr> for Expr

source§

fn from(x: QueryExpr) -> Self

Converts to this type from the input type.
source§

impl From<SourceExpr> for QueryExpr

source§

fn from(source: SourceExpr) -> Self

Converts to this type from the input type.
source§

impl Hash for QueryExpr

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for QueryExpr

source§

fn eq(&self, other: &QueryExpr) -> 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 Relation for QueryExpr

source§

fn head(&self) -> &Arc<Header>

source§

fn row_count(&self) -> RowCount

Specify the size in rows of the Relation. Read more
source§

impl Eq for QueryExpr

source§

impl StructuralPartialEq for QueryExpr

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.