Re: Function result cacheing - any comments?

From: Joe Conway <mail(at)joeconway(dot)com>
To: Philip Warner <pjw(at)rhyme(dot)com(dot)au>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Function result cacheing - any comments?
Date: 2002-08-19 05:29:35
Message-ID: 3D60823F.5000900@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Philip Warner wrote:
> So the obvious question is - in the opinion of people who know the code,
> can a function-result-cache be implemented with a lifetime of a single
> statement, without butchering the function manager?
>

I don't know if I fully understand what you're proposing, but if I
understand it correctly, I think the table function feature in current
sources does just what you want already. If you can write your function
as a table function, the results are put in a tuplestore for the
duration of the statement, and rescanned when needed.

Your example ends up looking like this:

create table departments(id integer, name text, manager_id integer);
insert into departments values(1, 'manufacturing', 1);
insert into departments values(2, 'accounting', 2);

create table people(id integer, department_id, name text);
insert into people values(1, 1, 'mfg boss');
insert into people values(2, 2, 'acct boss');
insert into people values(3, 1, 'mfg emp');
insert into people values(4, 2, 'acct emp');

create type manager_names as (dept_id int, name text);

create function get_manager_names() returns setof manager_names as
'select d.id, p.name from departments d, people p
where p.id = d.manager_id' language sql;

select p.name, m.name as boss from people p, get_manager_names() m where
p.department_id = m.dept_id;
name | boss
-----------+-----------
mfg boss | mfg boss
mfg emp | mfg boss
acct boss | acct boss
acct emp | acct boss
(4 rows)

Is this anything close what you had in mind?

Joe

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Philip Warner 2002-08-19 05:51:43 Re: Function result cacheing - any comments?
Previous Message Marc G. Fournier 2002-08-19 04:50:46 Re: Removing Libraries (Was: Re: Open 7.3 issues)