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
impl QueryExpr
pub fn new<T: Into<SourceExpr>>(source: T) -> Self
sourcepub fn walk_sources<E>(
&self,
on_source: &mut impl FnMut(&SourceExpr) -> Result<(), E>
) -> Result<(), E>
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.
sourcepub fn reads_from_table(&self, id: &TableId) -> bool
pub fn reads_from_table(&self, id: &TableId) -> bool
Does this query read from a given table?
pub fn with_index_eq( self, table: DbTable, columns: ColList, value: AlgebraicValue ) -> Self
pub fn with_index_lower_bound( self, table: DbTable, columns: ColList, value: AlgebraicValue, inclusive: bool ) -> Self
pub fn with_index_upper_bound( self, table: DbTable, columns: ColList, value: AlgebraicValue, inclusive: bool ) -> Self
pub fn with_select<O>(self, op: O) -> Self
pub fn with_select_cmp<LHS, RHS, O>(self, op: O, lhs: LHS, rhs: RHS) -> Self
pub fn with_project( self, cols: &[FieldExpr], wildcard_table_id: Option<TableId> ) -> Self
pub fn with_join_inner( self, with: impl Into<QueryExpr>, lhs: FieldName, rhs: FieldName, semi: bool ) -> Self
sourcepub fn try_semi_join(self) -> QueryExpr
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
JoinInnermust be the first (0th) element of thequery. Future work could search through thequeryto find any applicableJoinInners, but the current implementation inspects only the first expr. This is likely sufficient because this optimization is primarily useful for enablingtry_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 withDbTablesources, which results in anIndexJointhen we replace the sources withMemTables and go back to a [JoinInner] withsemi: true. - The
Projectmust immediately follow theJoinInner, 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 aMemTable. 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.
pub fn optimize(self, row_count: &impl Fn(TableId, &str) -> i64) -> Self
Trait Implementations§
source§impl AuthAccess for QueryExpr
impl AuthAccess for QueryExpr
source§impl From<SourceExpr> for QueryExpr
impl From<SourceExpr> for QueryExpr
source§fn from(source: SourceExpr) -> Self
fn from(source: SourceExpr) -> Self
Converts to this type from the input type.
source§impl PartialEq for QueryExpr
impl PartialEq for QueryExpr
impl Eq for QueryExpr
impl StructuralPartialEq for QueryExpr
Auto Trait Implementations§
impl Freeze for QueryExpr
impl RefUnwindSafe for QueryExpr
impl Send for QueryExpr
impl Sync for QueryExpr
impl Unpin for QueryExpr
impl UnwindSafe for QueryExpr
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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