Expand description
SPG execution engine — v0.3 wires the SQL front-end to the in-memory
storage layer. Implements CREATE TABLE, single-row INSERT VALUES, and
SELECT * FROM <table> (no WHERE yet — that lands in v0.4 alongside
expression evaluation against rows).
Re-exports§
pub use crate::users::Role;pub use crate::users::ScramSecrets;pub use crate::users::UserError;pub use crate::users::UserStore;
Modules§
- aggregate
- Aggregate executor.
- copy
- v7.22 (mailrs round-13 / T2) — shared COPY text-format helpers.
- describe
- v6.3.3 — Describe statement pre-Execute.
- eval
- Expression evaluator. Given a parsed
Expr, aRow, and the row’s column schema, produce aValue. v0.4 implements: - fts
- v7.12.1 — full-text search lexer / stemmer.
- json
- v4.14 minimal JSON parser for the
->/->>operators. - memoize
- v6.2.6 — Memoize cache for correlated subqueries.
- plan_
cache - v6.3.0 — Engine-level plan cache.
- publications
- v6.1.2 — logical-replication publication catalog.
- query_
stats - v6.5.1 — per-distinct-SQL LRU stat collector.
- reorder
- v6.2.3 — JOIN reorder planner pass.
- selectivity
- v6.2.2 — selectivity estimation over per-column statistics.
- statistics
- v6.2.0 — per-column statistics for the cost-based optimizer.
- subscriptions
- v6.1.4 — logical-replication subscription catalog.
- triggers
- v7.12.4 — PL/pgSQL row-level trigger executor.
- users
- User table + RBAC types for v4.1.
Structs§
- Activity
Row - v6.5.2 — one row of
spg_stat_activity. Engine-public so spg-server can construct rows without re-exporting internal dispatch types. - Audit
Row - v6.5.3 — one row of
spg_audit_chain. Engine-public so spg-server can construct rows directly fromAuditEntry. - Cancel
Token - Catalog
Snapshot - v7.11.0 — frozen read-only view of the engine’s committed state.
Constructed via
Engine::clone_snapshot. Holds clones of the catalog, statistics, clock function, and row-cap config — the four fields theexecute_readonlypath actually reads. Cheap toClone(each clone shares the underlyingPersistentVecrow storage; only the trie root pointers copy). Send + Sync so a snapshot can be moved acrosstokio::task::spawn_blockingboundaries without coordination. - Engine
- Engine
Snapshot - CoW-1 (v7.34) — frozen view of the persisted committed engine
state. Carries every field the
snapshot()envelope serializes;Cloneis O(1) on the catalog (Arc bump) and cheap typed-clones on the trailers. Decouples “capture state” from “serialize bytes” so the background-checkpoint worker can hold the snapshot and produce bytes off the engine write lock. - Memory
Stats - v7.31 — whole-engine memory snapshot: the polling form of the
round-26 ask-4 watermark signal. Hosts compare
total_approx_resident_bytes(+ their own WAL/file accounting) against their deployment ceiling and shed/shrink before the kernel does it for them. - Table
Memory Stats - v7.31 (memory campaign — ceiling-first / never-die, design v1) —
per-table slice of the engine’s resident-memory accounting.
hot_encoded_bytesis the storage layer’s maintained meter (what the rows encode to);approx_resident_bytesis what they COST in RAM (per-cell enum slots + heap payloads viaapprox_row_bytes) — the gap between the two is the representation multiplier the round-26 report measured at ~11× end-to-end. - TxId
- v4.5 cooperative cancellation token. A long-running SELECT /
UPDATE / DELETE checks
is_cancelledat row-loop checkpoints and bails withEngineError::Cancelled. The host (spg-server) creates anAtomicBoolper query, spawns a watchdog thread that sets it afterSPG_QUERY_TIMEOUT_MS, and passes it viaexecute_with_cancel/execute_readonly_with_cancel.
Enums§
- Engine
Error - All errors the engine can return.
- Parsed
Statement - Query
Result - Result of executing one statement.
- Stream
Item - v7.37 — one item in the streaming SELECT emit channel. The
engine yields exactly one
Header(before any row) then zero or moreRows. Pgwire (or any other consumer) decides how to turn those into wire bytes.
Constants§
- COMPACTION_
TARGET_ DEFAULT_ BYTES - v6.7.3 — default segment-size threshold used by
COMPACT COLD SEGMENTSwhen no explicit target is supplied. Segments whoseOwnedSegment::bytes().len()is strictly less than this value are eligible to merge. spg-server readsSPG_COMPACTION_TARGET_SEGMENT_BYTESto override. - IMPLICIT_
TX - Reserved slot used by
Engine::execute(sql)— the legacy single- global-shadow path. Newalloc_tx_idhandles start at 1.
Functions§
- format_
bigint_ 2d_ text_ pub - format_
hstore_ text - v7.17.0 Phase 3.P0-39 — pub re-export so pgwire + sqllogictest share the single hstore renderer.
- format_
int_ 2d_ text_ pub - v7.17.0 Phase 3.P0-40 — pub re-exports so pgwire + sqllogictest share the single 2D-array renderer.
- format_
range_ text - v7.17.0 Phase 3.P0-38 — render a Range value as its canonical
PG text form. Re-exported via
format_range_textfor use from spg-server’s pgwire layer. - format_
text_ 2d_ text_ pub - substitute_
placeholders - v7.16.0 — walks a parsed statement and replaces every
Expr::Placeholder(N)with the correspondingparams[N-1]re-encoded as anExpr::Literal. Used internally byEngine::execute_preparedAND surfaced for the spg-embedded WAL path (which needs the bind-final AST so replay sees a simple-query-shaped statement, not a$1-shaped one). Errors when a placeholder references an index past the params slice.
Type Aliases§
- Activity
Provider - v6.5.2 — provider callback type. Fresh snapshot returned each call; engine doesn’t cache the slice.
- Audit
Chain Provider - v6.5.3 — chain-table provider + verifier. spg-server registers
fn pointers that snapshot / verify the audit log.
verifyreturns(verified_count, broken_at_seq)—broken_at_seqis-1on a clean chain. - Audit
Verifier - ClockFn
- The execution engine. Holds the catalog and (later) other server-scope
state.
Engine::new()is intentionally cheap so callers can construct one per database, per test. Function pointer that returns “now” as microseconds since Unix epoch. The engine isno_std, so it can’t reach forstd::timeitself — callers (spg-server, the sqllogictest runner) inject a concrete implementation.NonemeansNOW()/CURRENT_*raiseUnsupported. - Monotonic
NowFn - v7.17.0 Phase 2.3 — monotonic time source for deadline-aware
cancellation (PG
statement_timeout). Returns microseconds since some host-stable monotonic origin (typically the first call intoInstant::now()on the server). The engine never callsInstant::now()directly so the crate stays#![no_std]. - SaltFn
- Function pointer that produces 16 cryptographically random bytes.
Like
ClockFn, the engine isno_stdand can’t reach for /dev/urandom itself — host (spg-server) injects an OS-backed source.Nonemeans SQL-drivenCREATE USERfalls back to a deterministic salt derived from the username (acceptable in tests; the server always installs a real RNG so production paths never see this). - Slow
Query Logger - v6.5.6 — callback signature for slow-query log emission. Called
with
(sql, elapsed_us)once per successful execute that crosses the threshold.