Skip to main content

Crate spg_engine

Crate spg_engine 

Source
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.
describe
v6.3.3 — Describe statement pre-Execute.
eval
Expression evaluator. Given a parsed Expr, a Row, and the row’s column schema, produce a Value. v0.4 implements:
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.
users
User table + RBAC types for v4.1.

Structs§

ActivityRow
v6.5.2 — one row of spg_stat_activity. Engine-public so spg-server can construct rows without re-exporting internal dispatch types.
AuditRow
v6.5.3 — one row of spg_audit_chain. Engine-public so spg-server can construct rows directly from AuditEntry.
CancelToken
v4.5 cooperative cancellation token. A long-running SELECT / UPDATE / DELETE checks is_cancelled at row-loop checkpoints and bails with EngineError::Cancelled. The host (spg-server) creates an AtomicBool per query, spawns a watchdog thread that sets it after SPG_QUERY_TIMEOUT_MS, and passes it via execute_with_cancel / execute_readonly_with_cancel.
CatalogSnapshot
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 the execute_readonly path actually reads. Cheap to Clone (each clone shares the underlying PersistentVec row storage; only the trie root pointers copy). Send + Sync so a snapshot can be moved across tokio::task::spawn_blocking boundaries without coordination.
Engine
TxId
v4.41.1 opaque transaction handle. Returned by Engine::alloc_tx_id, threaded through Engine::execute_in so dispatch can identify which in-flight TX a statement belongs to. IMPLICIT_TX is the reserved slot every legacy caller — engine self-tests, spg-cli, spg-embedded, startup replay — implicitly uses through the unchanged Engine::execute(sql) API. v4.41.1 keeps at most one active slot at runtime (dispatch holds engine.write() across the wrap, same as v4.34); the map shape is here to let v4.42 turn on N in-flight implicit TXs without reshuffling the engine internals.

Enums§

EngineError
All errors the engine can return.
QueryResult
Result of executing one statement.

Constants§

COMPACTION_TARGET_DEFAULT_BYTES
v6.7.3 — default segment-size threshold used by COMPACT COLD SEGMENTS when no explicit target is supplied. Segments whose OwnedSegment::bytes().len() is strictly less than this value are eligible to merge. spg-server reads SPG_COMPACTION_TARGET_SEGMENT_BYTES to override.
IMPLICIT_TX
Reserved slot used by Engine::execute(sql) — the legacy single- global-shadow path. New alloc_tx_id handles start at 1.

Type Aliases§

ActivityProvider
v6.5.2 — provider callback type. Fresh snapshot returned each call; engine doesn’t cache the slice.
AuditChainProvider
v6.5.3 — chain-table provider + verifier. spg-server registers fn pointers that snapshot / verify the audit log. verify returns (verified_count, broken_at_seq)broken_at_seq is -1 on a clean chain.
AuditVerifier
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 is no_std, so it can’t reach for std::time itself — callers (spg-server, the sqllogictest runner) inject a concrete implementation. None means NOW() / CURRENT_* raise Unsupported.
SaltFn
Function pointer that produces 16 cryptographically random bytes. Like ClockFn, the engine is no_std and can’t reach for /dev/urandom itself — host (spg-server) injects an OS-backed source. None means SQL-driven CREATE USER falls 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).
SlowQueryLogger
v6.5.6 — callback signature for slow-query log emission. Called with (sql, elapsed_us) once per successful execute that crosses the threshold.