caches lifetime with SQL vs PL/PGSQL procs

From: strk(at)refractions(dot)net
To: pgsql-hackers(at)postgresql(dot)org
Cc: postgis-devel(at)postgis(dot)refractions(dot)net
Subject: caches lifetime with SQL vs PL/PGSQL procs
Date: 2005-03-16 12:04:03
Message-ID: 20050316120403.GN17570@freek.keybit.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On postgresql-8.0.0 I've faced a *really* weird behavior.

A simple query (single table - simple function call - no index),
makes postgres process grow about as much as the memory size required
to keep ALL rows in memory.

The invoked procedure call doesn't leak.
It's IMMUTABLE.
Calls other procedures (not leaking).

Now.
One of the other procedures it calls is an 'SQL' one.
Replacing it with a correponding 'PL/PGSQL' implementation
drastically reduces memory occupation:

SQL: 220Mb
PL/PGSQL: 13Mb

The function body is *really* simple:

-- SQL
CREATE OR REPLACE FUNCTION get_proj4_from_srid(integer) RETURNS text AS
'SELECT proj4text::text FROM spatial_ref_sys WHERE srid= $1'
LANGUAGE 'sql' IMMUTABLE STRICT;

-- PL/PGSQL
CREATE OR REPLACE FUNCTION get_proj4_from_srid(integer) RETURNS text AS
' BEGIN
RETURN proj4text::text FROM spatial_ref_sys WHERE srid= $1;
END
' LANGUAGE 'plpgsql' IMMUTABLE STRICT;

Is this expected ?

--strk;

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Pradier 2005-03-16 12:18:24 Re: Erratic error message "ERROR: column "id_compte" does
Previous Message Hannu Krosing 2005-03-16 11:58:54 Re: signed short fd