pub struct QueryPlan {Show 13 fields
pub source: QuerySource,
pub projection: Vec<SelectExpr>,
pub joins: Vec<JoinExpr>,
pub filter: Option<Expr>,
pub grouping: Vec<Expr>,
pub having: Option<Expr>,
pub ordering: Vec<OrderExpr>,
pub limit: Option<u64>,
pub offset: Option<u64>,
pub distinct: DistinctMode,
pub lock: Option<LockMode>,
pub compound: Vec<Compound>,
pub origin: Option<PlanOrigin>,
}Expand description
Backend-neutral read query.
Built immutably: every builder method consumes and returns self, so a
QuerySet can clone a base plan and branch safely.
Fields§
§source: QuerySourceRoot source.
projection: Vec<SelectExpr>Projection; empty means “all columns of the root source”.
joins: Vec<JoinExpr>Joins.
filter: Option<Expr>WHERE.
grouping: Vec<Expr>GROUP BY.
having: Option<Expr>HAVING.
ordering: Vec<OrderExpr>ORDER BY.
limit: Option<u64>LIMIT.
offset: Option<u64>OFFSET.
distinct: DistinctModeDistinct mode.
lock: Option<LockMode>Row lock.
compound: Vec<Compound>Queries combined with this one (UNION …). ordering, limit and
offset of this plan then apply to the combined result, and every
member must project the same number of columns.
origin: Option<PlanOrigin>Database the plan was built against, recorded when a QuerySet
becomes a subquery. Never compiled; Db uses it to reject a subquery
that belongs to another database.
Implementations§
Source§impl QueryPlan
impl QueryPlan
Sourcepub fn from_table(table: impl Into<Ident>) -> Self
pub fn from_table(table: impl Into<Ident>) -> Self
Plan selecting every row of table.
Sourcepub fn from_subquery(inner: QueryPlan, alias: impl Into<Ident>) -> Self
pub fn from_subquery(inner: QueryPlan, alias: impl Into<Ident>) -> Self
Plan selecting every row of the derived table (inner) AS alias.
Sourcepub fn select(self, expr: impl Into<Expr>, alias: Option<&'static str>) -> Self
pub fn select(self, expr: impl Into<Expr>, alias: Option<&'static str>) -> Self
Add a projected expression.
Sourcepub fn exclude(self, predicate: Expr) -> Self
pub fn exclude(self, predicate: Expr) -> Self
AND the negation of a predicate into the filter (Django exclude).
Sourcepub fn order_by(self, expr: impl Into<Expr>, direction: OrderDirection) -> Self
pub fn order_by(self, expr: impl Into<Expr>, direction: OrderDirection) -> Self
Append an ordering term.
Sourcepub fn join(self, kind: JoinKind, source: QuerySource, on: Expr) -> Self
pub fn join(self, kind: JoinKind, source: QuerySource, on: Expr) -> Self
Add a join.
Sourcepub fn distinct(self, mode: DistinctMode) -> Self
pub fn distinct(self, mode: DistinctMode) -> Self
Set distinct mode.
Sourcepub fn required_features(&self) -> Vec<Feature>
pub fn required_features(&self) -> Vec<Feature>
Features this plan needs from a backend (deduplicated).
Sourcepub fn resolve_relations(self) -> Self
pub fn resolve_relations(self) -> Self
Replace Expr::Related columns by joined-table columns, adding the
needed LEFT JOINs (deduplicated by alias) to this plan and to nested
plans. Idempotent; querysets call it after every builder step.
Sourcepub fn has_foreign_origin(&self, origin: PlanOrigin) -> bool
pub fn has_foreign_origin(&self, origin: PlanOrigin) -> bool
Whether this plan, or any plan nested in it, was built against a
database other than origin.
Sourcepub fn check(
&self,
caps: &BackendCapabilities,
) -> Result<(), BackendCapabilityError>
pub fn check( &self, caps: &BackendCapabilities, ) -> Result<(), BackendCapabilityError>
Check the plan against backend capabilities.