Skip to main content

QueryPlan

Struct QueryPlan 

Source
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: QuerySource

Root 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: DistinctMode

Distinct 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

Source

pub fn from_table(table: impl Into<Ident>) -> Self

Plan selecting every row of table.

Source

pub fn from_subquery(inner: QueryPlan, alias: impl Into<Ident>) -> Self

Plan selecting every row of the derived table (inner) AS alias.

Source

pub fn select(self, expr: impl Into<Expr>, alias: Option<&'static str>) -> Self

Add a projected expression.

Source

pub fn filter(self, predicate: Expr) -> Self

AND a predicate into the filter.

Source

pub fn exclude(self, predicate: Expr) -> Self

AND the negation of a predicate into the filter (Django exclude).

Source

pub fn order_by(self, expr: impl Into<Expr>, direction: OrderDirection) -> Self

Append an ordering term.

Source

pub fn limit(self, n: u64) -> Self

Set LIMIT.

Source

pub fn offset(self, n: u64) -> Self

Set OFFSET.

Source

pub fn join(self, kind: JoinKind, source: QuerySource, on: Expr) -> Self

Add a join.

Source

pub fn lock(self, mode: LockMode) -> Self

Request a row lock.

Source

pub fn distinct(self, mode: DistinctMode) -> Self

Set distinct mode.

Source

pub fn required_features(&self) -> Vec<Feature>

Features this plan needs from a backend (deduplicated).

Source

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.

Source

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.

Source

pub fn check( &self, caps: &BackendCapabilities, ) -> Result<(), BackendCapabilityError>

Check the plan against backend capabilities.

Trait Implementations§

Source§

impl Clone for QueryPlan

Source§

fn clone(&self) -> QueryPlan

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QueryPlan

Source§

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

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

impl PartialEq for QueryPlan

Source§

fn eq(&self, other: &QueryPlan) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for QueryPlan

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more