Skip to content

Add $_SD: per-function static storage#1

Merged
jdatcmd merged 1 commit into
masterfrom
feature/sd-static-dict
Jul 7, 2026
Merged

Add $_SD: per-function static storage#1
jdatcmd merged 1 commit into
masterfrom
feature/sd-static-dict

Conversation

@jdatcmd

@jdatcmd jdatcmd commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds $_SD, a Hash private to each PL/Ruby function that persists across calls to that function within a session. This closes a PL/Python parity gap: $_SD is the counterpart of PL/Python's SD, where the existing $_SHARED is GD. It's the natural place to cache a prepared plan or other per-function state without colliding in the session-global $_SHARED.

Behavior

  • Each function's $_SD is independent (keyed by the internal proc name, so a function's trigger form and plain form are distinct too).
  • $_SD resets on CREATE OR REPLACE (tied to the compiled function; the entry is dropped alongside the proc cache on recompile).
  • An anonymous DO block gets a fresh, empty $_SD each run (no persistent identity); $_SHARED still persists everywhere.
  • Bound around dispatch with the same save/restore discipline as $_TD and the transform tables, so a body that re-enters PL/Ruby via SPI sees the correct $_SD.

Testing

New sql/sd regression test covering persistence, per-function isolation, $_SD vs $_SHARED, reset on CREATE OR REPLACE, and survival across an in-body error. Full suite green on PG 12 and PG 18 in the build container.

Purely additive; no compatibility impact.

🤖 Generated with Claude Code

$_SD is a Hash private to each function that persists across calls to
that function within a session -- the counterpart of PL/Python's SD,
where the existing $_SHARED is GD. It is the natural place to cache a
prepared plan or other per-function state without a name collision in
the session-global $_SHARED.

The hash is keyed by the function's internal proc name, so it is
distinct per function (and for a function's trigger vs plain form) and
is dropped when the function is recompiled, so $_SD resets on CREATE OR
REPLACE. The call handler binds it around dispatch with the same
save/restore discipline as $_TD and the transform tables, so a body that
re-enters PL/Ruby via SPI sees the right $_SD. An anonymous DO block gets
a fresh, empty $_SD each run.

Tested on PG 12 and 18 (new sql/sd test).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jdatcmd jdatcmd merged commit 0ae8101 into master Jul 7, 2026
9 checks passed
@jdatcmd jdatcmd deleted the feature/sd-static-dict branch July 7, 2026 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant