Add $_SD: per-function static storage#1
Merged
Conversation
$_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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
$_SD, aHashprivate to each PL/Ruby function that persists across calls to that function within a session. This closes a PL/Python parity gap:$_SDis the counterpart of PL/Python'sSD, where the existing$_SHAREDisGD. It's the natural place to cache a prepared plan or other per-function state without colliding in the session-global$_SHARED.Behavior
$_SDis independent (keyed by the internal proc name, so a function's trigger form and plain form are distinct too).$_SDresets onCREATE OR REPLACE(tied to the compiled function; the entry is dropped alongside the proc cache on recompile).DOblock gets a fresh, empty$_SDeach run (no persistent identity);$_SHAREDstill persists everywhere.$_TDand the transform tables, so a body that re-enters PL/Ruby via SPI sees the correct$_SD.Testing
New
sql/sdregression test covering persistence, per-function isolation,$_SDvs$_SHARED, reset onCREATE 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