From: | Thomas Beutin <tyrone(at)laokoon(dot)IN-Berlin(dot)DE> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Fast statement but slow function |
Date: | 2002-05-08 09:21:43 |
Message-ID: | 20020508112143.A31020@laokoon.bug.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hallo,
i'm new to the the list but using postgres since the 6.x days.
Now i run into a problem creating a function instead of executing
the same statements many times. But there is a _very__big_
performance difference between the results.
The following statement executes very fast (less than a half
of a second) on my installation:
SELECT count(a_id) FROM (
SELECT DISTINCT a_id FROM o_kat_ausst AS k
WHERE k.l4_id = '140000000000007'
UNION
SELECT DISTINCT a_id FROM o_produkt AS p, o_adresse AS a, o_kat_prod AS k
WHERE a.id = p.a_id AND p.p_id = k.p_id AND k.l4_id = '140000000000007'
) AS foo;
but when i create the following function
CREATE FUNCTION "o_l4_a_id_count" (character)
RETURNS integer
AS 'SELECT count(a_id) FROM (
SELECT DISTINCT a_id FROM o_kat_ausst AS k
WHERE k.l4_id = $1
UNION
SELECT DISTINCT a_id FROM o_produkt AS p, o_adresse AS a, o_kat_prod AS k
WHERE a.id = p.a_id AND p.p_id = k.p_id AND k.l4_id = $1
) AS foo;'
LANGUAGE 'sql';
and do the statement
SELECT o_l4_a_id_count('140000000000007');
it takes more than 4 seconds.
Is this a bug in my function or in my mind or in postgres?
Are functions using indexes?
This problem happens on versionis 7.1.2 and 7.2.1 (i just have
to change the return value for the function to bigint instead of int).
I checked all indices on involved tables but can't find a mistake.
BTW: I'm using the same functions with the l1_id, l2_id, l3_id instead
of l4_id, and these functions looks as fast as the real statements.
Thanks for reading and help!
-tb
--
Thomas Beutin tb(at)laokoon(dot)IN-Berlin(dot)DE
Beam me up, Scotty. There is no intelligent live down in Redmond.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-05-08 14:10:29 | Re: Allow user to create tables |
Previous Message | Tille, Andreas | 2002-05-08 07:34:38 | Re: Allow user to create tables |