Are user defined functions in postgres (and greenplum) run in isolation? How many execution environments are open when I have a query with a plpythonu user-defined functions? Is there any shared python interpreter state when running a query?
Say I have a plpython user defined function:
CREATE OR REPLACE FUNCTION file2text(path string) RETURNS text AS $$
f = open(path, 'r')
return f.read()
f.close()
$$ LANGUAGE plpythonu;
For a table create table files (name varchar, path varchar)
and a query over that table as follows:
SELECT f.name
FROM files f
WHERE character_length( file2text(f.path) ) > 4096
ORDER BY f.name
Is a new python environment spawned for each execution of my plpython function? In a MPP databases, can I assume that the behavior of postgres be duplicated across each segment with no shared state across segments?