Struct mz_sql::query_model::Model
source · pub struct Model {
pub(crate) top_box: BoxId,
boxes: HashMap<BoxId, Box<RefCell<QueryBox>>>,
box_id_gen: Gen<BoxId>,
quantifiers: HashMap<QuantifierId, Box<RefCell<Quantifier>>>,
quantifier_id_gen: Gen<QuantifierId>,
}Expand description
A Query Graph Model instance represents a SQL query. See the design doc for details.
In this representation, SQL queries are represented as a graph of operators, represented as boxes, that are connected via quantifiers. A top-level box represents the entry point of the query.
Each non-leaf box has a set of quantifiers, which are the inputs of the operation it represents. The quantifier adds information about how the relation represented by its input box is consumed by the parent box.
Fields§
§top_box: BoxIdThe ID of the box representing the entry-point of the query.
boxes: HashMap<BoxId, Box<RefCell<QueryBox>>>All boxes in the query graph model.
box_id_gen: Gen<BoxId>Used for assigning unique IDs to query boxes.
quantifiers: HashMap<QuantifierId, Box<RefCell<Quantifier>>>All quantifiers in the query graph model.
quantifier_id_gen: Gen<QuantifierId>Used for assigning unique IDs to quantifiers.
Implementations§
source§impl Model
impl Model
Helper methods for the derivation of the RelationType attribute.
sourcefn cols_type(&self, box_id: BoxId) -> Vec<ColumnType> ⓘ
fn cols_type(&self, box_id: BoxId) -> Vec<ColumnType> ⓘ
Infers a vector of ColumnType values for the columns
of the given BoxId.
Note: this method should be used only internally in order
to derive the RelationType attribute of a Model.
sourcefn expr_type(&self, expr: &BoxScalarExpr, enclosing_box_id: BoxId) -> ColumnType
fn expr_type(&self, expr: &BoxScalarExpr, enclosing_box_id: BoxId) -> ColumnType
Infers a ColumnType corresponding to the given
BoxScalarExpr used within the context of an
enclosing BoxId.
Note: this method should be used only internally in order
to derive the RelationType attribute of a Model.
sourcefn cref_type(&self, cref: &ColumnReference, enclosing_box_id: BoxId) -> ColumnType
fn cref_type(&self, cref: &ColumnReference, enclosing_box_id: BoxId) -> ColumnType
Looks up a ColumnType corresponding to the given
ColumnReference from the RelationType attribute
of the input box, assuming the ColumnReference
occurs within the context of the enclosing BoxId.
Note: this method should be used only internally in order
to derive the RelationType attribute of a Model.
source§impl Model
impl Model
pub(crate) fn make_box(&mut self, box_type: BoxType) -> BoxId
pub(crate) fn make_select_box(&mut self) -> BoxId
sourcepub(crate) fn boxes_iter(&self) -> impl Iterator<Item = BoundRef<'_, QueryBox>>
pub(crate) fn boxes_iter(&self) -> impl Iterator<Item = BoundRef<'_, QueryBox>>
sourcepub(crate) fn get_box(&self, box_id: BoxId) -> BoundRef<'_, QueryBox>
pub(crate) fn get_box(&self, box_id: BoxId) -> BoundRef<'_, QueryBox>
Get an immutable reference to the box identified by box_id bound to this Model.
sourcepub(crate) fn get_mut_box(&mut self, box_id: BoxId) -> BoundRefMut<'_, QueryBox>
pub(crate) fn get_mut_box(&mut self, box_id: BoxId) -> BoundRefMut<'_, QueryBox>
Get a mutable reference to the box identified by box_id bound to this Model.
sourcepub(crate) fn make_quantifier(
&mut self,
quantifier_type: QuantifierType,
input_box: BoxId,
parent_box: BoxId
) -> QuantifierId
pub(crate) fn make_quantifier(
&mut self,
quantifier_type: QuantifierType,
input_box: BoxId,
parent_box: BoxId
) -> QuantifierId
Create a new quantifier and adds it to the parent box
sourcepub(crate) fn get_quantifier<'a>(
&'a self,
quantifier_id: QuantifierId
) -> BoundRef<'a, Quantifier>
pub(crate) fn get_quantifier<'a>(
&'a self,
quantifier_id: QuantifierId
) -> BoundRef<'a, Quantifier>
Get an immutable reference to the box identified by box_id bound to this Model.
sourcepub(crate) fn get_mut_quantifier<'a>(
&'a mut self,
quantifier_id: QuantifierId
) -> BoundRefMut<'a, Quantifier>
pub(crate) fn get_mut_quantifier<'a>(
&'a mut self,
quantifier_id: QuantifierId
) -> BoundRefMut<'a, Quantifier>
Get a mutable reference to the box identified by box_id bound to this Model.
sourcepub(crate) fn try_visit_pre_post<'a, F, G, E>(
&'a self,
pre: &mut F,
post: &mut G
) -> Result<(), E>where
F: FnMut(&Model, &BoxId) -> Result<(), E>,
G: FnMut(&Model, &BoxId) -> Result<(), E>,
pub(crate) fn try_visit_pre_post<'a, F, G, E>(
&'a self,
pre: &mut F,
post: &mut G
) -> Result<(), E>where
F: FnMut(&Model, &BoxId) -> Result<(), E>,
G: FnMut(&Model, &BoxId) -> Result<(), E>,
sourcepub(crate) fn try_visit_pre_post_descendants<'a, F, G, E>(
&'a self,
pre: &mut F,
post: &mut G,
root: BoxId
) -> Result<(), E>where
F: FnMut(&Model, &BoxId) -> Result<(), E>,
G: FnMut(&Model, &BoxId) -> Result<(), E>,
pub(crate) fn try_visit_pre_post_descendants<'a, F, G, E>(
&'a self,
pre: &mut F,
post: &mut G,
root: BoxId
) -> Result<(), E>where
F: FnMut(&Model, &BoxId) -> Result<(), E>,
G: FnMut(&Model, &BoxId) -> Result<(), E>,
sourcepub(crate) fn try_visit_mut_pre_post<'a, F, G, E>(
&'a mut self,
pre: &mut F,
post: &mut G
) -> Result<(), E>where
F: FnMut(&mut Model, &BoxId) -> Result<(), E>,
G: FnMut(&mut Model, &BoxId) -> Result<(), E>,
pub(crate) fn try_visit_mut_pre_post<'a, F, G, E>(
&'a mut self,
pre: &mut F,
post: &mut G
) -> Result<(), E>where
F: FnMut(&mut Model, &BoxId) -> Result<(), E>,
G: FnMut(&mut Model, &BoxId) -> Result<(), E>,
Same as Model::try_visit_pre_post, but permits mutating the model.
sourcepub(crate) fn try_visit_mut_pre_post_descendants<'a, F, G, E>(
&'a mut self,
pre: &mut F,
post: &mut G,
root: BoxId
) -> Result<(), E>where
F: FnMut(&mut Model, &BoxId) -> Result<(), E>,
G: FnMut(&mut Model, &BoxId) -> Result<(), E>,
pub(crate) fn try_visit_mut_pre_post_descendants<'a, F, G, E>(
&'a mut self,
pre: &mut F,
post: &mut G,
root: BoxId
) -> Result<(), E>where
F: FnMut(&mut Model, &BoxId) -> Result<(), E>,
G: FnMut(&mut Model, &BoxId) -> Result<(), E>,
Same as Model::try_visit_pre_post_descendants, but permits mutating the model.
sourcepub(crate) fn garbage_collect(&mut self)
pub(crate) fn garbage_collect(&mut self)
Removes unreferenced objects from the model.
May be invoked several times during query rewrites.
sourcepub(crate) fn update_ids(&mut self)
pub(crate) fn update_ids(&mut self)
Renumbers all the boxes and quantifiers in the model starting from 0.
Intended to be called after Model::garbage_collect.
Renumbering the model does not save memory or improve the performance of traversing the model, but it does make the Dot graph easier to parse.
Trait Implementations§
source§impl TryFrom<HirRelationExpr> for Model
impl TryFrom<HirRelationExpr> for Model
source§impl TryFrom<Model> for HirRelationExpr
impl TryFrom<Model> for HirRelationExpr
Auto Trait Implementations§
impl !RefUnwindSafe for Model
impl Send for Model
impl !Sync for Model
impl Unpin for Model
impl !UnwindSafe for Model
Blanket Implementations§
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Requestsource§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto.source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto.