Skip to main content

SelectStatement

Struct SelectStatement 

Source
pub struct SelectStatement {
Show 16 fields pub locking: Option<Box<LockingClause>>, pub ctes: Vec<Cte>, pub distinct: bool, pub distinct_on: Vec<Expr>, pub items: Vec<SelectItem>, pub from: Option<FromClause>, pub where_: Option<Expr>, pub group_by: Option<Vec<Expr>>, pub group_by_all: bool, pub having: Option<Expr>, pub unions: Vec<(UnionKind, SelectStatement)>, pub order_by: Vec<OrderBy>, pub limit: Option<LimitExpr>, pub offset: Option<LimitExpr>, pub limit_with_ties: bool, pub window_check_exprs: Vec<Expr>,
}

Fields§

§locking: Option<Box<LockingClause>>

v7.39 (round 293, E3 Phase 1) — FOR UPDATE and friends. The clause was parsed and DISCARDED since v7.17, so SPG accepted the whole syntax and locked nothing: two workers running the classic SKIP LOCKED queue take both took the same row. v7.39 (round 305) — boxed. A locking clause appears on a vanishing fraction of SELECTs, but an inline Option<LockingClause> cost every SelectStatement 32 bytes, and this struct sits in recursive evaluation frames where the engine already runs close to its stack budget (a 512 KB depth guard is the canary).

§ctes: Vec<Cte>

v4.11: WITH name AS (SELECT ...) [, ...] common-table expressions, materialised once at query start before the body SELECT runs. Empty for a regular SELECT. Non-recursive only — no WITH RECURSIVE for v4.x.

§distinct: bool§distinct_on: Vec<Expr>

v7.37.17 (17.6 siblings) — SELECT DISTINCT ON (exprs): keep the first row (per ORDER BY) of each group the expressions define. Empty = no DISTINCT ON.

§items: Vec<SelectItem>§from: Option<FromClause>§where_: Option<Expr>§group_by: Option<Vec<Expr>>§group_by_all: bool

v6.4.1 — GROUP BY ALL shortcut: when true, the planner expands group_by to every non-aggregate SELECT-list item before the executor runs. Mutually exclusive with an explicit group_by list (the parser sets exactly one).

§having: Option<Expr>

HAVING <expr> — filter applied after GROUP BY aggregation. Supports aggregate calls (e.g. HAVING count(*) > 1); the aggregate executor resolves them through the same synthetic schema used for the SELECT items.

§unions: Vec<(UnionKind, SelectStatement)>

UNION / UNION ALL chain. Empty for a plain SELECT. Each peer is itself a SelectStatement with order_by = None and limit = None (the parser enforces that — ORDER BY / LIMIT belong to the top of the chain).

§order_by: Vec<OrderBy>

v6.4.0 — multi-key ORDER BY. Empty Vec means no ORDER BY. Keys are matched left-to-right: first key decides, ties break to the second, etc.

§limit: Option<LimitExpr>

LIMIT <n> — bound on row output. n is an integer literal or (v7.9.24) a placeholder $N resolved against the prepared-statement Bind values. mailrs migration follow-up H2.

§offset: Option<LimitExpr>

OFFSET <n> — drop the first n rows after ORDER BY but before LIMIT (so LIMIT 10 OFFSET 5 keeps rows 6..=15).

§limit_with_ties: bool

v7.17.0 Phase 3.P0-49 — FETCH FIRST <n> ROWS WITH TIES (SQL:2008). When true and an ORDER BY is present, the executor extends past the LIMIT-truncated tail to include every row whose ORDER BY key equals the last-kept row’s key. Requires an ORDER BY; the executor errors otherwise (matching PG’s WITH TIES rule). The parser was already accepting WITH TIES since Phase 5.1; this field captures the choice so the executor can act on it.

§window_check_exprs: Vec<Expr>

v7.39 (round 705) — the key expressions of WINDOW-clause definitions that NOTHING referenced. PG analyses every definition whether referenced or not, so WINDOW w AS (ORDER BY nosuch) fails there and silently succeeded here — the referenced ones get their columns resolved through the WindowFunction nodes they were inlined into, and the unreferenced ones used to be dropped at parse, unexamined. The engine resolves these with a LIMIT-0 probe of the same FROM.

Not part of Display: an unreferenced definition has no effect on the result, so a deparsed body (a stored view) omits it.

Implementations§

Source§

impl SelectStatement

v7.9.24 — extract LIMIT / OFFSET as a u32 literal. After the engine’s substitute_placeholders pass these are always Literal; in the simple-query path a Placeholder shape returns None (executor surfaces as “LIMIT/OFFSET ${n} requires prepared-statement binding”).

Source

pub fn limit_literal(&self) -> Option<u32>

Source

pub fn offset_literal(&self) -> Option<u32>

Trait Implementations§

Source§

impl Clone for SelectStatement

Source§

fn clone(&self) -> SelectStatement

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 SelectStatement

Source§

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

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

impl Default for SelectStatement

Source§

fn default() -> SelectStatement

Returns the “default value” for a type. Read more
Source§

impl Display for SelectStatement

Source§

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

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

impl PartialEq for SelectStatement

Source§

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

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.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.