From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Richard Huxton <dev(at)archonet(dot)com> |
Cc: | Heiko Stoermer <heiko(dot)stoermer(at)login-solutions(dot)de>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Stored procedure returning row or resultset |
Date: | 2002-10-14 17:17:32 |
Message-ID: | 17131.1034615852@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Richard Huxton <dev(at)archonet(dot)com> writes:
> Have you looked at marking f1() etc cachable? This means Postgresql
> will only call the function once for each parameter-set.
Unfortunately that's not true at all, or at least not helpful for this
problem. The cachable attribute was poorly named, because it leads
people to think that PG *will* cache function results, as opposed to
*could* cache function results.
A possible workaround is along the lines of
SELECT f1, f1 + f2, f1 + f2 + f3 FROM
(SELECT f1() as f1, f2() as f2, f3() as f3 LIMIT 1) tmp;
Note the LIMIT 1 ... without that, the planner may flatten the two
levels of SELECT together, eliminating the savings you're trying for.
(I don't recall offhand all the conditions that govern flattening
of a sub-select, but I'm pretty sure a sub-LIMIT will prevent it.)
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Brian Ward | 2002-10-15 01:21:37 | functions that return a dataset or set of rows |
Previous Message | Brian Blaha | 2002-10-14 15:15:04 | Re: Stored procedure returning row or resultset |