| @@ -972,6 +972,46 @@ |
| 972 | 972 | - **If flipped:** offer an opt-in eager snapshot (force the whole subtree at the boundary) |
| 973 | 973 | while keeping lazy the default — the same escape hatch RD-6 describes. |
| 974 | 974 | |
| 975 | +### RD-10: feel-pg volatility — STABLE `feel_eval`, plus an IMMUTABLE `feel_eval_immutable` |
| 976 | + |
| 977 | +- **Weighed:** `feel_eval` shipped as the pgrx default (VOLATILE, PARALLEL UNSAFE), |
| 978 | + which over-constrains the planner and bars the function from index expressions. |
| 979 | + But the evaluator is referentially transparent: no global mutable state, I/O or |
| 980 | + randomness (ADR-1), context output is `BTreeMap`-ordered, and the *only* ambient |
| 981 | + input is the instant behind `now()`/`today()` (ADR-18), which feel-pg pins to the |
| 982 | + transaction start. That makes `feel_eval` precisely **STABLE** (the same reason |
| 983 | + PostgreSQL's own `transaction_timestamp()` is STABLE) and **PARALLEL SAFE** (a |
| 984 | + parallel worker is a separate process with its own `fn_extra` cache). It cannot be |
| 985 | + IMMUTABLE — `now()` differs across transactions. The pull toward an immutable |
| 986 | + surface is concrete: expression indexes (and generated columns, constant folding) |
| 987 | + over a `jsonb` column require an IMMUTABLE callee. Three hazards to a "pure" subset: |
| 988 | + (1) `now()`/`today()`; (2) *named* IANA zones, whose offset is read from the |
| 989 | + updatable tzdb; (3) `exp`/`log`/`sqrt` and the regex builtins, stable only up to a |
| 990 | + libc / `regex`-crate version. |
| 991 | +- **Decision (2026-06-17, implemented):** keep one STABLE `feel_eval` and add a |
| 992 | + second, IMMUTABLE `feel_eval_immutable`, rather than overloading volatility on one |
| 993 | + function — a function has a single volatility class, and mislabelling one silently |
| 994 | + corrupts any index built on it. Both are PARALLEL SAFE and `COST 100` (PostgreSQL's |
| 995 | + default for a non-trivial/procedural function; a parse-cached eval of a low-to-medium |
| 996 | + FEEL expression sits there, so the planner orders cheaper quals ahead of it). |
| 997 | + `feel_eval_immutable` enforces determinism in two layers, both in feel-core: |
| 998 | + a *static* clock check (`CompiledExpr::is_clock_free`, cached in `fn_extra`) that |
| 999 | + **hard-ERRORs** on `now()`/`today()`; and a *runtime* named-zone ban |
| 1000 | + (`EvalEnv::forbidding_named_zones`) that turns a named zone into null (ERROR under |
| 1001 | + `strict => true`). Fixed offsets and `Z` are kept — they are tzdb-independent and |
| 1002 | + all an index needs. Math/regex are accepted as immutable: a libc/`regex` upgrade is |
| 1003 | + rare and at worst wants a one-off `REINDEX`, the same pragmatic stance PostgreSQL |
| 1004 | + takes for its own such functions. The named-zone ban is applied at the only sites |
| 1005 | + that can mint one — the `@"…"` literal and the `time()`/`date and time()` string |
| 1006 | + constructors — so a named zone can never exist to leak through a later comparison. |
| 1007 | +- **Revisit trigger:** a need for named zones *inside* an index (then a |
| 1008 | + tzdb-version-pinned variant, or a generated UTC-normalised column), or evidence that |
| 1009 | + `COST 100` mis-orders plans for very heavy expressions (raise it, or make it |
| 1010 | + expression-aware). |
| 1011 | +- **If flipped (drop the immutable subset):** delete `feel_eval_immutable` and the two |
| 1012 | + feel-core seams (`is_clock_free`, `forbidding_named_zones`/`vet_named_zone`); callers |
| 1013 | + needing an index would precompute the value into a stored column via a trigger. |
| 1014 | + |
| 975 | 1015 | ## Roadmap: deferred scope (recorded, not yet built) |
| 976 | 1016 | |
| 977 | 1017 | These were considered and deliberately deferred to keep the slice thin. Listed so |