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.
Functions§
- default_
registry - Access the shared default registry.
- fold_
constant - Fold a
SqlExprto a literalSqlValueat plan time, or returnNoneif the expression depends on row/runtime state (column refs, subqueries, unknown functions, etc.). - fold_
constant_ default - Convenience wrapper around
fold_constantusing the default registry. - 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 inregistry, so callers can distinguish “unknown function” from “known function, all args folded”.