Re: plpgsql functing does not use index.... - Mailing list pgsql-novice

From Stephan Szabo
Subject Re: plpgsql functing does not use index....
Date
Msg-id 20040712164530.O38194@megazone.bigpanda.com
Whole thread Raw
In response to plpgsql functing does not use index....  (Ralf Hasemann <rhasemann@mac.com>)
List pgsql-novice
On Mon, 12 Jul 2004, Ralf Hasemann wrote:

> I call the function with: select * from
> fnc_selAdressByName('Hasemann%', 5, 0);
> The request takes about 22 sec.
>
> When I execute the query of the function directly:
> select * from public.adressen where name like 'Hasemann%'  order by
> name  limit 5 offset 0
> the request takes about 0.058 sec.
>
> So I get the idea that the query uesn in the plpgsql function did not
> use the adressen_ixname index.
>
> Why????? What can I do to make it use the index?????

Because the query is basically planned without knowledge of the arguments
because it's saved for later calls. While the index scan works for
'Hasemann%', it doesn't for '%foo' for example. In addition, it won't know
what limit and offset you're going to use. If you want to force it to plan
with the arguments passed, you can use the plpgsql FOR ... IN EXECUTE
querystring version.

pgsql-novice by date:

Previous
From: Frank Bax
Date:
Subject: Re: plpgsql functing does not use index....
Next
From: "Werner vd Merwe"
Date:
Subject: PostgreSQL Performance issues