Re: [GENERAL] Tuning queries inside a function

2005-05-03 Thread Richard Huxton
Mike Nolan wrote: Maybe you could return a refcursor pointing to the EXPLAIN ANALYZE of the query inside the function. The raw materials exist to do this: if you know which elements of a query will be replaced by plpgsql variables, you can duplicate the results via PREPARE foo(...) AS ...

Re: [GENERAL] Tuning queries inside a function

2005-05-02 Thread Tom Lane
"Joshua D. Drake" <[EMAIL PROTECTED]> writes: > Mike Nolan wrote: >> That part I get, but I cannot seem to get an 'explain select' to return >> the explain output inside a function. > Oh interesting. Hmmm. Alvaro can you think of a way to execute the > result into a variable and return it as

Re: [GENERAL] Tuning queries inside a function

2005-05-02 Thread Joshua D. Drake
Mike Nolan wrote: Mike Nolan wrote: select * from foo('bar','debug') But how do I do that inside a pl/pgsql function? 'select into' doesn't seem to work properly. You would have to code it. For example: IF $2 = ''debug'' THEN: That part I get, but I cannot seem to get an 'explain select' to

Re: [GENERAL] Tuning queries inside a function

2005-05-02 Thread Mike Nolan
> Mike Nolan wrote: > >>select * from foo('bar','debug') > > > > > > But how do I do that inside a pl/pgsql function? 'select into' doesn't > > seem to work properly. > > > You would have to code it. For example: > > IF $2 = ''debug'' THEN: That part I get, but I cannot seem to get an 'expla

Re: [GENERAL] Tuning queries inside a function

2005-05-02 Thread Joshua D. Drake
Mike Nolan wrote: select * from foo('bar','debug') But how do I do that inside a pl/pgsql function? 'select into' doesn't seem to work properly. You would have to code it. For example: IF $2 = ''debug'' THEN: I would have to check be able to include a timestamp at the beginning of each notice

Re: [GENERAL] Tuning queries inside a function

2005-04-30 Thread Mike Nolan
> > Maybe you could return a refcursor pointing to the EXPLAIN ANALYZE of > > the query inside the function. > > The raw materials exist to do this: if you know which elements of a > query will be replaced by plpgsql variables, you can duplicate the > results via > > PREPARE foo(...) AS ...

Re: [GENERAL] Tuning queries inside a function

2005-04-29 Thread Tom Lane
Alvaro Herrera <[EMAIL PROTECTED]> writes: > On Fri, Apr 29, 2005 at 12:32:26PM -0500, Mike Nolan wrote: >> Any ideas on how to tune a user function? > Maybe you could return a refcursor pointing to the EXPLAIN ANALYZE of > the query inside the function. The raw materials exist to do this: if you

Re: [GENERAL] Tuning queries inside a function

2005-04-29 Thread Tony Caduto
We have functions with upwards of 800 lines and we simply pull the queries out and stick them in the PG Lighting Admin or PG Admin III query editor. We then substitue any vars etc with real values. Works ok. > What's the best way to tune the queries inside a user function? > > I have a fairl

Re: [GENERAL] Tuning queries inside a function

2005-04-29 Thread Mike Nolan
> select * from foo('bar','debug') But how do I do that inside a pl/pgsql function? 'select into' doesn't seem to work properly. > I would have to check be able to include a timestamp at the beginning > of each notice. You can do that from the config file, but it only gives the time to the ne

Re: [GENERAL] Tuning queries inside a function

2005-04-29 Thread Joshua D. Drake
Huh, sorry, this doesn't work ... we don't allow DECLARE for EXPLAIN. It'd be neat though ... What about having a debug mode for the function. E.g: selet * from foo('bar','debug') When you run with debug it actually runs the function but outputs notices that are the explain anaylze of each function

Re: [GENERAL] Tuning queries inside a function

2005-04-29 Thread Alvaro Herrera
On Fri, Apr 29, 2005 at 02:38:30PM -0400, Alvaro Herrera wrote: > On Fri, Apr 29, 2005 at 12:32:26PM -0500, Mike Nolan wrote: > > > I need to find out if the function can be tuned further, but 'explain' > > doesn't really tell much about what's happening inside the function. > > > > Any ideas on

Re: [GENERAL] Tuning queries inside a function

2005-04-29 Thread Alvaro Herrera
On Fri, Apr 29, 2005 at 12:32:26PM -0500, Mike Nolan wrote: > I need to find out if the function can be tuned further, but 'explain' > doesn't really tell much about what's happening inside the function. > > Any ideas on how to tune a user function? Maybe you could return a refcursor pointing to