pub enum LimitExpr {
Literal(u32),
Placeholder(u16),
Expr(Box<Expr>),
}Expand description
v7.9.24 — LIMIT / OFFSET value. Integer literal at parse
time or a placeholder $N resolved during extended-query
Bind. mailrs migration follow-up H2.
v7.39 (round 305) — no longer Copy/Eq: the Expr variant boxes
an arbitrary row-count expression. Losing Copy is deliberate — it
made the compiler point at every site that used to duplicate a
row-count out of the AST, which is exactly the set that must not
bypass the resolution pre-pass.
Variants§
Literal(u32)
LIMIT 10 — value known at parse time.
Placeholder(u16)
LIMIT $N — the 1-based parameter index, resolved against
the bind values when the prepared statement executes.
Expr(Box<Expr>)
v7.39 (round 305, V23) — LIMIT (SELECT 4) / LIMIT greatest(2,3): a row-count expression that isn’t constant, so
it can’t be folded at parse time. Evaluated once, before
dispatch, by the engine’s resolve_limit_exprs pre-pass, which
rewrites it to Literal (or to None for a NULL result, PG’s
“no limit”). No execution path may see this variant —
as_literal would report None, which every row-count reader
takes to mean “unlimited”, i.e. the whole table.
Implementations§
Source§impl LimitExpr
impl LimitExpr
Sourcepub fn as_literal(&self) -> Option<u32>
pub fn as_literal(&self) -> Option<u32>
Convenience for the simple-query path where no placeholders
can possibly exist. Returns the literal value or None if
this is a placeholder (caller must surface as Unsupported).
v7.39 (round 305) — None is read by every row-count consumer as
“no limit”. An unresolved LimitExpr::Expr reaching here would
therefore silently return the whole table, so the engine’s
resolve_limit_exprs pre-pass rewrites the variant away before
dispatch. The assertion makes a missed nesting site fail loudly
in every test build rather than quietly widening a result set.