Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Don't hold type I/O caches inter execusions.
Browse files Browse the repository at this point in the history
Split JavaScript function cache and type I/O function caches.
Type I/O cache lives as same as the original function memory context.
  • Loading branch information
ItGacky committed Oct 3, 2011
1 parent d1f5015 commit 4f1bed5
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 100 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MODULE_big = plv8
EXTENSION = plv8
DATA = plv8.control plv8--1.0.sql
DATA_built = plv8.sql
REGRESS = init-extension plv8 inline
REGRESS = init-extension plv8 inline json
override SHLIB_LINK += -lv8

CCFLAGS := $(filter-out -Wmissing-prototypes, $(CFLAGS))
Expand Down
37 changes: 37 additions & 0 deletions expected/json.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CREATE FUNCTION valid_json(json text) RETURNS boolean
LANGUAGE plv8 IMMUTABLE STRICT
AS $$
try {
JSON.parse(json);
return true;
} catch(e) {
return false;
}
$$;
CREATE DOMAIN json AS text
CONSTRAINT json_check CHECK (valid_json(VALUE));
CREATE FUNCTION get_key(key text, json_raw text) RETURNS json
LANGUAGE plv8 IMMUTABLE STRICT
AS $$
var val = JSON.parse(json_raw)[key];
var ret = {};
ret[key] = val;
return JSON.stringify(ret);
$$;
CREATE TABLE jsononly (
data json
);
COPY jsononly (data) FROM stdin;
-- Call twice to test the function cache.
SELECT get_key('ok', data) FROM jsononly;
get_key
-------------
{"ok":true}
(1 row)

SELECT get_key('ok', data) FROM jsononly;
get_key
-------------
{"ok":true}
(1 row)

Loading

0 comments on commit 4f1bed5

Please sign in to comment.