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.

Functions§

default_registry
Access the shared default registry.
fold_constant
Fold a SqlExpr to a literal SqlValue at plan time, or return None if the expression depends on row/runtime state (column refs, subqueries, unknown functions, etc.).
fold_constant_default
Convenience wrapper around fold_constant using 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 in registry, so callers can distinguish “unknown function” from “known function, all args folded”.