Skip to main content

Module const_fold

Module const_fold 

Source
Expand description

Plan-time constant folding for SqlExpr.

Evaluates literal expressions and registered zero-or-few-arg scalar functions (e.g. now(), current_timestamp, date_add(now(), '1h')) at plan time via the shared nodedb_query::functions::eval_function evaluator.

This keeps the bare-SELECT projection path, the INSERT/UPSERT VALUES path, and any future default-expression paths from drifting apart — they all reach the same evaluator that the Data Plane uses for column-reference evaluation.

Semantics: Postgres / SQL-standard compatible. now() and current_timestamp snapshot once per statement — CURRENT_TIMESTAMP is defined to return the same value for every row of a single statement, and Postgres goes further (same value for the whole transaction). Folding at plan time satisfies both contracts and is cheaper than per-row runtime dispatch.

Enums§

FoldScope
Whether a fold is allowed to evaluate Volatile functions.

Functions§

default_registry
Access the shared default registry.
fold_constant
Fold a SqlExpr to a literal SqlValue at plan time. See FoldResult for what each outcome means. Volatile calls are never folded.
fold_constant_default
Convenience wrapper around fold_constant using the default registry.
fold_constant_scoped
Fold a SqlExpr under an explicit FoldScope.
fold_function_call
Fold a function call by recursively folding its arguments, dispatching through the shared scalar evaluator, and converting the result back to SqlValue. Only folds functions that are present in registry, so callers can distinguish “unknown function” from “known function, all args folded”. A Volatile function is never folded.
fold_function_call_scoped
Fold a function call under an explicit FoldScope.

Type Aliases§

FoldResult
Outcome of folding a constant expression.