-- Creating or replacing one function must not throw away every user's compiled -- state. The previous behaviour was a full pljs_cache_reset(), which destroys the -- per-user JSContext -- and JS_FreeContext() will not free a context that still -- has live references, so a backend doing repeated DDL grew without bound. -- -- Whether the context survived is observable from JavaScript: anything held on -- globalThis lives in that context, so it is still there after unrelated DDL -- exactly when the context was not destroyed. CREATE FUNCTION tin_set() RETURNS void AS $$ globalThis.tin_marker = 'kept'; $$ LANGUAGE pljs; CREATE FUNCTION tin_get() RETURNS text AS $$ return globalThis.tin_marker || '(gone)'; $$ LANGUAGE pljs; SELECT tin_set(); tin_set --------- (1 row) SELECT tin_get() AS before_ddl; before_ddl ------------ kept (1 row) -- DDL on an unrelated function. CREATE FUNCTION tin_other() RETURNS int AS $$ return 1; $$ LANGUAGE pljs; SELECT tin_get() AS after_unrelated_create; after_unrelated_create ------------------------ kept (1 row) CREATE OR REPLACE FUNCTION tin_other() RETURNS int AS $$ return 2; $$ LANGUAGE pljs; SELECT tin_get() AS after_unrelated_replace; after_unrelated_replace ------------------------- kept (1 row) -- The replaced function itself does pick up its new body, which is the whole point -- of invalidating anything at all. SELECT tin_other() AS new_body; new_body ---------- 2 (1 row) DROP FUNCTION tin_set, tin_get, tin_other;