(PostgreSQL 7.3.2 on i386-portbld-freebsd4.7, compiled by GCC 2.95.4)
I've a curious performance problem with a function returning set of
rows. The query alone is very fast, but not when called from the
To "emulate" a parametred view¹, I created a function as follow:
CREATE FUNCTION get_info (integer) RETURNS SETOF type_get_info
AS '...' <- here the query show below, where 'LIMIT $1' is used instead of 'LIMIT 10'
The table table1 have 330K rows, and table2 have 3K rows.
When I run the following query (prefixed with SELECT * to try to get
the same behavior that the second query), I obtain very good time.
database=# SELECT * FROM (
FROM table1 AS a, table1 AS b
ORDER BY a.field6 DESC
FROM table2 AS a, table1 AS b
ORDER BY a.field4 DESC
ORDER BY field4 DESC
) AS type_get_info;
Time: 185.86 ms
But, when I run the function (with 10 as parameter, but even 1 is
slow) I get poor time:
database=# SELECT * FROM get_info(10);
Time: 32782.26 ms
(even after a VACUUM FULL ANALYZE, and REINDEX of indexes used in the
What is curious is that I remember that the function was fast at a
What is the difference between the two case ?
 Is there another solution to this 'hack' ? I can't simply create a
view and use 'LIMIT 10' because intermediate SELECT have be limited
too (to avoid UNION with 300K rows where only the first 10 are of
interest to me.)
pgsql-performance by date
|Next:||From: Frederic Jolliton||Date: 2003-04-24 15:47:53|
|Subject: Re: Important speed difference between a query and a|
|Previous:||From: Greg Stark||Date: 2003-04-23 16:32:09|
|Subject: Re: [SQL] Yet Another (Simple) Case of Index not used|